merve HF staff commited on
Commit
c52039d
β€’
1 Parent(s): 6876b98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -19,11 +19,11 @@ def query(payload):
19
  context = "To extract information from documents, use sentence similarity task. To do sentiment analysis from tweets, use text classification task. To detect masks from images, use object detection task. To extract information from invoices, use named entity recognition from token classification task."
20
 
21
 
22
- message_history = ["Let's find out the best task for your use case! Tell me about your use case :)"]
23
 
24
 
25
  for msg in message_history:
26
- message(msg) # display all the previous message
27
 
28
  placeholder = st.empty() # placeholder for latest message
29
  input = st.text_input("Ask me πŸ€—")
@@ -36,6 +36,7 @@ with placeholder.container():
36
 
37
 
38
  message(input, is_user=True) # align's the message to the right
 
39
 
40
  data, resp = query(
41
  {
@@ -46,10 +47,13 @@ data, resp = query(
46
  }
47
  )
48
  if resp.status_code == 200:
 
49
  model_answer = data["answer"]
50
  response_templates = [f"{model_answer} is the best task for this 🀩", f"I think you should use {model_answer} πŸͺ„", f"I think {model_answer} should work for you πŸ€“"]
 
51
  bot_answer = random.choice(response_templates)
52
- message_history.append(bot_answer)
 
53
 
54
 
55
 
 
19
  context = "To extract information from documents, use sentence similarity task. To do sentiment analysis from tweets, use text classification task. To detect masks from images, use object detection task. To extract information from invoices, use named entity recognition from token classification task."
20
 
21
 
22
+ message_history = [{"text":"Let's find out the best task for your use case! Tell me about your use case :)", is_user = False}]
23
 
24
 
25
  for msg in message_history:
26
+ message(msg["text"], is_user = msg["is_user"]) # display all the previous message
27
 
28
  placeholder = st.empty() # placeholder for latest message
29
  input = st.text_input("Ask me πŸ€—")
 
36
 
37
 
38
  message(input, is_user=True) # align's the message to the right
39
+ message_history.append({"text":input, "is_user" = True})
40
 
41
  data, resp = query(
42
  {
 
47
  }
48
  )
49
  if resp.status_code == 200:
50
+
51
  model_answer = data["answer"]
52
  response_templates = [f"{model_answer} is the best task for this 🀩", f"I think you should use {model_answer} πŸͺ„", f"I think {model_answer} should work for you πŸ€“"]
53
+
54
  bot_answer = random.choice(response_templates)
55
+
56
+ message_history.append({"text":bot_answer, "is_user" : False})
57
 
58
 
59