Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
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 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
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 |
+
|