Commit 951e74b4 authored by Jiang, Genze's avatar Jiang, Genze
Browse files

Delete print in web app source code

parent 88ef06ab
......@@ -45,21 +45,17 @@ def before_request():
#ip_addr=request.headers['X-Real-Ip']
total_user = user_info.query.filter_by(ip_addr=ip_addr).all()
if len(total_user) > 3:
print("more than 3 !!!")
user_delete = user_info.query.filter_by(ip_addr=ip_addr).first()
db.session.delete(user_delete)
db.session.commit()
user_id = fm.generate_random_str(8)
fm.mkdir('./static/user/' + user_id)
print(user_id + "created")
session['user'] = user_id
file_name = session['user']
expired_time = datetime.now() + timedelta(days=1)
user_insert = user_info(file_name, ip_addr, expired_time)
db.session.add(user_insert)
db.session.commit()
else:
print(session.get('user') + " has existed")
@app.route("/")
......@@ -244,7 +240,6 @@ def inpaint():
inpainted_image_name = img_name_no_extension + "_inpainted" + img_extension
save_path = folder_path + inpainted_image_name
print(save_path)
if not os.path.isfile(save_path):
# Load the inpainter
try:
......@@ -330,9 +325,7 @@ def predict():
f"Your uploaded image and text combination "
f"looks like a <strong>{hateful}</strong> meme, with {cls_confidence * 100: .2f}% confidence. "
)
print(cls_result)
t0 = datetime.now()
try:
if exp_method == "shap":
text_exp, img_exp, txt_msg, img_msg = shap_mmf.shap_multimodal_explain(
......@@ -390,9 +383,6 @@ def predict():
)
return redirect(url_for("hateful_memes"))
elapsed = datetime.now() - t0
print(f"predicting using {exp_method} took {elapsed.seconds: .2f} seconds.")
session["clsResult"] = cls_result
session["imgText"] = img_text
session["textExp"] = text_exp
......@@ -401,12 +391,10 @@ def predict():
exp_text_visl, _ = os.path.splitext(img_exp)
exp_text_visl = exp_text_visl[:-4] + "_txt.png"
print(txt_msg, img_msg)
session["txtMsg"] = txt_msg
session["imgMsg"] = img_msg
try:
print(text_exp)
ut.text_visualisation(text_exp, cls_label, exp_text_visl)
session["textExp"] = exp_text_visl
except:
......@@ -416,11 +404,6 @@ def predict():
)
session["textExp"] = None
print(session["imgText"])
print(session["textExp"])
print(session["imgExp"])
print(session["modelPath"])
flash(
"Done! Hover over the output images to see how to interpret the results",
"success",
......
......@@ -31,9 +31,9 @@ def prepare_explanation(
try:
model = setup_model(user_model, model_type, model_path)
except InputError as e:
raise InputError(e.message()) from e # TODO: customise error classes
raise InputError(e.message()) from e
model = model.to(torch.device("cuda:0" if torch.cuda.is_available() else "cpu"))
model.to(torch.device("cuda:0" if torch.cuda.is_available() else "cpu"))
img = Image.open(img_name)
try:
......@@ -139,8 +139,6 @@ def text_visualisation(exp, pred_res, save_path):
else:
plt_title = "not hateful"
print(exp)
# handle different output formats from explainers
vals = []
names = []
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment