File size: 2,112 Bytes
563692c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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)