Spaces:
Sleeping
Sleeping
File size: 1,560 Bytes
3d2ccf5 93b20f9 3d2ccf5 050bcdd 39fa1f9 c7680ca 3d2ccf5 5d2b7f0 8d84f6e 5d2b7f0 3d2ccf5 1fc7fac 3d2ccf5 173a459 93b20f9 c2425d0 173a459 f95ba2d 3d2ccf5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import streamlit as st
import requests
import os
from streamlit_chat import message
import random
@st.cache
def query(payload):
api_token = os.getenv("api_token")
model_id = "deepset/roberta-base-squad2"
headers = {"Authorization": f"Bearer {api_token}"}
API_URL = f"https://api-inference.huggingface.co/models/{model_id}"
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
message("Let's find out the best task for your use case! Tell me about your use case :)")
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."
#for message_ in message_history:
# message(message_) # display all the previous message
#placeholder = st.empty() # placeholder for latest message
input = st.text_input("Ask me π€")
message(input, is_user=True) # align's the message to the right
data = query(
{
"inputs": {
"question": input,
"context": context,
},
"options" : {"wait_for_model": True},
}
)
try:
bot_answer = data["answer"]
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 π€"]
message(random.choice(response_templates))
except:
message("I'm listening π ")
|