import streamlit as st import requests import os from streamlit_chat import message @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("What should I use to..") message(input, is_user=True) # align's the message to the right data = query( { "inputs": { "question": input, "context": context, } } ) bot_answer = data["answer"] message(f"{bot_answer} is the best task for this :)")