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