merve HF staff commited on
Commit
e413986
β€’
1 Parent(s): 850e742

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -25
app.py CHANGED
@@ -41,39 +41,40 @@ for msg in message_history:
41
 
42
  placeholder = st.empty() # placeholder for latest message
43
 
44
- input = st.text_input("Ask me πŸ€—")
45
- message_history.append({"text":input, "is_user" : True})
46
-
47
 
 
 
 
48
 
49
- data, resp = query(
50
  {
51
  "inputs": {
52
  "question": input,
53
  "context": context,
54
  }
55
  }
56
- )
57
-
58
 
59
- if resp.status_code == 200:
60
 
61
- model_answer = data["answer"]
62
- for key in link_dict:
63
- if key in model_answer:
64
- url = link_dict[key]
65
- response_templates = [f"I think that {model_answer} is the best task for this 🀩 Check out the page πŸ‘‰πŸΌ {url}", f"I think you should use {model_answer} πŸͺ„ Check it out here πŸ‘‰πŸΌ {url}", f"I think {model_answer} should work for you πŸ€“ Check out the page πŸ‘‰πŸΌ {url}"]
66
 
67
- bot_answer = random.choice(response_templates)
68
- message_history.append({"text":bot_answer, "is_user" : False})
69
- else:
70
- fallback_template = ["I didn't get the question 🧐 Could you please ask again? Try 'What should I use for detecting masks in an image?'",
71
- "Hmm, not sure I know the answer, maybe you could ask differently? πŸ€“",
72
- "Sorry, I didn't understand you, maybe you could ask differently? πŸ€“ Try asking 'What should I use to extract name in a document' πŸ€—"]
73
- bot_answer = random.choice(fallback_template)
74
-
75
- with placeholder.container():
76
- last_message = message_history[-1]
77
- if last_message != "":
78
- message(last_message["text"], last_message["is_user"])
79
-
 
 
 
 
 
 
 
 
41
 
42
  placeholder = st.empty() # placeholder for latest message
43
 
 
 
 
44
 
45
+ input = st.text_input("Ask me πŸ€—")
46
+ if input:
47
+ message_history.append({"text":input, "is_user" : True})
48
 
49
+ data, resp = query(
50
  {
51
  "inputs": {
52
  "question": input,
53
  "context": context,
54
  }
55
  }
56
+ )
 
57
 
 
58
 
59
+ if resp.status_code == 200:
 
 
 
 
60
 
61
+ model_answer = data["answer"]
62
+ for key in link_dict:
63
+ if key in model_answer:
64
+ url = link_dict[key]
65
+ response_templates = [f"I think that {model_answer} is the best task for this 🀩 Check out the page πŸ‘‰πŸΌ {url}", f"I think you should use {model_answer} πŸͺ„ Check it out here πŸ‘‰πŸΌ {url}", f"I think {model_answer} should work for you πŸ€“ Check out the page πŸ‘‰πŸΌ {url}"]
66
+
67
+ bot_answer = random.choice(response_templates)
68
+ message_history.append({"text":bot_answer, "is_user" : False})
69
+ else:
70
+ fallback_template = ["I didn't get the question 🧐 Could you please ask again? Try 'What should I use for detecting masks in an image?'",
71
+ "Hmm, not sure I know the answer, maybe you could ask differently? πŸ€“",
72
+ "Sorry, I didn't understand you, maybe you could ask differently? πŸ€“ Try asking 'What should I use to extract name in a document' πŸ€—"]
73
+ bot_answer = random.choice(fallback_template)
74
+
75
+ with placeholder.container():
76
+ last_message = message_history[-1]
77
+ if last_message != "":
78
+ message(last_message["text"], last_message["is_user"])
79
+
80
+