merve HF staff commited on
Commit
1b8a80e
β€’
1 Parent(s): 8d84f6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -2,7 +2,6 @@ import streamlit as st
2
  import requests
3
  import os
4
  from streamlit_chat import message
5
- import random
6
 
7
 
8
  @st.cache
@@ -14,15 +13,23 @@ def query(payload):
14
  response = requests.post(API_URL, headers=headers, json=payload)
15
  return response.json()
16
 
17
- message("Let's find out the best task for your use case! Tell me about your use case :)")
 
 
18
  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."
19
 
20
- #for message_ in message_history:
21
- # message(message_) # display all the previous message
22
 
23
- #placeholder = st.empty() # placeholder for latest message
24
 
25
- input = st.text_input("Ask me πŸ€—")
 
 
 
 
 
 
 
 
 
26
  message(input, is_user=True) # align's the message to the right
27
 
28
  data = query(
@@ -30,16 +37,15 @@ data = query(
30
  "inputs": {
31
  "question": input,
32
  "context": context,
33
- },
34
- "options" : {"wait_for_model": True},
35
  }
36
  )
37
  try:
38
  bot_answer = data["answer"]
39
- response_templates = [f"{bot_answer} is the best task for this 🀩", f"I think you should use {bot_answer} πŸͺ„", f"I think {bot_answer} should work for you πŸ€“"]
40
- message(random.choice(response_templates))
41
 
42
  except:
43
- message("I'm listening πŸ‘€ ")
 
44
 
45
 
 
2
  import requests
3
  import os
4
  from streamlit_chat import message
 
5
 
6
 
7
  @st.cache
 
13
  response = requests.post(API_URL, headers=headers, json=payload)
14
  return response.json()
15
 
16
+
17
+
18
+ st.title("Let's find out the best task for your use case! Tell me about your use case :)")
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
 
23
+ for message_ in message_history:
24
+ message(message_) # display all the previous message
25
+
26
+ placeholder = st.empty() # placeholder for latest message
27
+ input = st.text_input("You:")
28
+ message_history.append(input)
29
+
30
+ with placeholder.container():
31
+ message(message_history[-1]) # display the latest message
32
+
33
  message(input, is_user=True) # align's the message to the right
34
 
35
  data = query(
 
37
  "inputs": {
38
  "question": input,
39
  "context": context,
40
+ }
 
41
  }
42
  )
43
  try:
44
  bot_answer = data["answer"]
45
+ message(f"{bot_answer} is the best task for this :)")
 
46
 
47
  except:
48
+ message("Inference API is currently loading!")
49
+
50
 
51