Spaces:
Runtime error
Runtime error
Commit
·
563692c
1
Parent(s):
457a558
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
from io import BytesIO
|
4 |
+
import base64
|
5 |
+
import streamlit as st
|
6 |
+
|
7 |
+
AUTH_TOKEN = st. secrets["AUTH_TOKEN"]
|
8 |
+
|
9 |
+
headers = {"Authorization": f"Bearer {AUTH_TOKEN}"}
|
10 |
+
st.set_page_config(page_title="Image Similarity", page_icon="🎆🎇")
|
11 |
+
CHAT_API = "https://abhilashvj-chat-api.hf.space/"
|
12 |
+
# IMAGE_SIMILARITY_DEMO = "http://127.0.0.1:8000/find-similar-image-pinecone/"
|
13 |
+
TMP_DIR = "./tmp"
|
14 |
+
|
15 |
+
os.makedirs(TMP_DIR, exist_ok=True)
|
16 |
+
|
17 |
+
st.title("Document Uploader and Chatbot Trainer")
|
18 |
+
|
19 |
+
st.header("Upload Documents")
|
20 |
+
|
21 |
+
# Upload evergreen document
|
22 |
+
evergreen_file = st.file_uploader("Choose an Evergreen Document", type=['txt', 'pdf', 'doc', 'docx'])
|
23 |
+
if evergreen_file:
|
24 |
+
files = {'file': evergreen_file.getvalue()}
|
25 |
+
response = requests.post(f'{CHAT_API}upload/evergreen/', files=files, headers=headers)
|
26 |
+
if response.json().get("success"):
|
27 |
+
st.success("Evergreen document uploaded successfully!")
|
28 |
+
else:
|
29 |
+
st.error("Failed to upload evergreen document!")
|
30 |
+
|
31 |
+
# Upload dynamic document
|
32 |
+
dynamic_file = st.file_uploader("Choose a Dynamic Document", type=['txt', 'pdf', 'doc', 'docx'])
|
33 |
+
if dynamic_file:
|
34 |
+
files = {'file': dynamic_file.getvalue()}
|
35 |
+
response = requests.post(f'{CHAT_API}upload/dynamic/', files=files, headers=headers)
|
36 |
+
if response.json().get("success"):
|
37 |
+
st.success("Dynamic document uploaded successfully!")
|
38 |
+
else:
|
39 |
+
st.error("Failed to upload dynamic document!")
|
40 |
+
|
41 |
+
# Train bot button
|
42 |
+
# if st.button("Train Bot"):
|
43 |
+
# response = requests.post('http://your_fastapi_endpoint/train/')
|
44 |
+
# bot_url = response.json().get("bot_url")
|
45 |
+
# if bot_url:
|
46 |
+
# st.success(f"Bot trained successfully! Access the bot at {bot_url}")
|
47 |
+
# else:
|
48 |
+
# st.error("Failed to train the bot!")
|
49 |
+
|
50 |
+
# Chat with bot
|
51 |
+
st.header("Chat with Bot")
|
52 |
+
user_input = st.text_input("Ask your question:")
|
53 |
+
# Assuming you have an endpoint to send user questions and get responses
|
54 |
+
data = {
|
55 |
+
"text": user_input,
|
56 |
+
"top_k": 5,
|
57 |
+
}
|
58 |
+
response = requests.post(f'{CHAT_API}/query/', json=data)
|
59 |
+
bot_response = response.json().get("answer")
|
60 |
+
st.text_area("Bot's Response:", value=bot_response)
|