import os import requests from io import BytesIO import base64 import streamlit as st AUTH_TOKEN = st. secrets["AUTH_TOKEN"] headers = {"Authorization": f"Bearer {AUTH_TOKEN}"} st.set_page_config(page_title="Image Similarity", page_icon="🎆🎇") CHAT_API = "https://abhilashvj-chat-api.hf.space/" # IMAGE_SIMILARITY_DEMO = "http://127.0.0.1:8000/find-similar-image-pinecone/" TMP_DIR = "./tmp" os.makedirs(TMP_DIR, exist_ok=True) st.title("Document Uploader and Chatbot Trainer") st.header("Upload Documents") # Upload evergreen document evergreen_file = st.file_uploader("Choose an Evergreen Document", type=['txt', 'pdf', 'doc', 'docx']) if evergreen_file: files = {'file': evergreen_file.getvalue()} response = requests.post(f'{CHAT_API}upload/evergreen/', files=files, headers=headers) if response.json().get("success"): st.success("Evergreen document uploaded successfully!") else: st.error("Failed to upload evergreen document!") # Upload dynamic document dynamic_file = st.file_uploader("Choose a Dynamic Document", type=['txt', 'pdf', 'doc', 'docx']) if dynamic_file: files = {'file': dynamic_file.getvalue()} response = requests.post(f'{CHAT_API}upload/dynamic/', files=files, headers=headers) if response.json().get("success"): st.success("Dynamic document uploaded successfully!") else: st.error("Failed to upload dynamic document!") # Train bot button # if st.button("Train Bot"): # response = requests.post('http://your_fastapi_endpoint/train/') # bot_url = response.json().get("bot_url") # if bot_url: # st.success(f"Bot trained successfully! Access the bot at {bot_url}") # else: # st.error("Failed to train the bot!") # Chat with bot st.header("Chat with Bot") user_input = st.text_input("Ask your question:") # Assuming you have an endpoint to send user questions and get responses data = { "text": user_input, "top_k": 5, } response = requests.post(f'{CHAT_API}/query/', json=data) bot_response = response.json().get("answer") st.text_area("Bot's Response:", value=bot_response)