merve HF staff commited on
Commit
3d2ccf5
1 Parent(s): a434297

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import os
4
+ from streamlit_chat import message
5
+
6
+
7
+ api_token = os.getenv("api_token")
8
+
9
+ @st.cache
10
+ def query(payload, model_id, api_token):
11
+ headers = {"Authorization": f"Bearer {api_token}"}
12
+ API_URL = f"https://api-inference.huggingface.co/models/{model_id}"
13
+ response = requests.post(API_URL, headers=headers, json=payload)
14
+ return response.json()
15
+
16
+ message("Let's find out the best task for your use case! Tell me about your use case :)")
17
+ 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."
18
+
19
+ #for message_ in message_history:
20
+ # message(message_) # display all the previous message
21
+
22
+ #placeholder = st.empty() # placeholder for latest message
23
+ input = st.text_input("What should I use to..")
24
+ message(input, is_user=True) # align's the message to the right
25
+
26
+ data = query(
27
+ {
28
+ "inputs": {
29
+ "question": input,
30
+ "context": context,
31
+ }
32
+ }
33
+ )
34
+
35
+ message(f"It's best to use {data["answer"]} for this :)")
36
+
37
+
38
+