Spaces:
Paused
Paused
Upload 4 files
Browse files- Pages/pages_File-chat.py +74 -0
- Pages/pages_Image-scan.py +67 -0
- Pages/pages_Web-chat.py +72 -0
- Pages/pages_error.py +18 -0
Pages/pages_File-chat.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import utils
|
4 |
+
|
5 |
+
# Custom CSS
|
6 |
+
with open('styles.css') as f:
|
7 |
+
css = f.read()
|
8 |
+
|
9 |
+
st.markdown(f'<style>{css}</style>', unsafe_allow_html=True)
|
10 |
+
|
11 |
+
## LOGO and TITLE
|
12 |
+
## -------------------------------------------------------------------------------------------
|
13 |
+
# Show the logo and title side by side
|
14 |
+
col1, col2 = st.columns([1, 4])
|
15 |
+
with col1:
|
16 |
+
st.image("brainbot.png", width=100)
|
17 |
+
with col2:
|
18 |
+
st.title("File-Chat")
|
19 |
+
|
20 |
+
question = None
|
21 |
+
llm = st.session_state["llm"]
|
22 |
+
|
23 |
+
if "current_file" in st.session_state:
|
24 |
+
current_file = st.session_state['current_file']
|
25 |
+
if st.sidebar.button("Upload New File"):
|
26 |
+
st.switch_page("BrainBot.py")
|
27 |
+
st.subheader("Your file has been uploaded successfully. You can now chat with it.")
|
28 |
+
st.success(current_file)
|
29 |
+
question = st.chat_input("Type your question here...")
|
30 |
+
|
31 |
+
else:
|
32 |
+
st.warning("Upload a file to begin chat with it.")
|
33 |
+
if st.button("Upload File"):
|
34 |
+
st.switch_page("BrainBot.py")
|
35 |
+
|
36 |
+
## CHAT
|
37 |
+
# Clear the file chat history if user has uploaded a new file
|
38 |
+
if st.session_state['uploaded_file'] == True:
|
39 |
+
st.session_state['file_chat_history'] = []
|
40 |
+
|
41 |
+
# Display the file chat history
|
42 |
+
for message in st.session_state['file_chat_history']:
|
43 |
+
with st.chat_message("user"):
|
44 |
+
st.write(message["Human"])
|
45 |
+
with st.chat_message("ai"):
|
46 |
+
st.markdown(utils.format_response(message["AI"]))
|
47 |
+
|
48 |
+
## QUESTION - WITH CHAT HISTORY
|
49 |
+
## -------------------------------------------------------------------------------------------
|
50 |
+
# Retrieve the answer to the question asked by the user
|
51 |
+
if question is not None:
|
52 |
+
# Display the question entered by the user in chat
|
53 |
+
with st.chat_message("user"):
|
54 |
+
st.write(question)
|
55 |
+
|
56 |
+
resource = "file"
|
57 |
+
|
58 |
+
try:
|
59 |
+
# Send POST request to a FastAPI endpoint to retrieve an answer for the question
|
60 |
+
data = {"question": question, "resource": resource}
|
61 |
+
FASTAPI_URL = f"http://localhost:8000/answer_with_chat_history/{llm}"
|
62 |
+
|
63 |
+
with st.spinner("Generating response..."):
|
64 |
+
response = requests.post(FASTAPI_URL, json=data)
|
65 |
+
# Append the response to the chat history
|
66 |
+
st.session_state['file_chat_history'].append({"Human": question, "AI": response.text})
|
67 |
+
st.session_state['uploaded_file'] = False
|
68 |
+
# Display the AI's response to the question in chat
|
69 |
+
with st.chat_message("ai"):
|
70 |
+
# Format the response
|
71 |
+
formatted_response = utils.format_response(response.text)
|
72 |
+
st.markdown(formatted_response)
|
73 |
+
except Exception as e:
|
74 |
+
st.switch_page("error.py")
|
Pages/pages_Image-scan.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import utils
|
4 |
+
|
5 |
+
# Custom CSS
|
6 |
+
with open('styles.css') as f:
|
7 |
+
css = f.read()
|
8 |
+
|
9 |
+
st.markdown(f'<style>{css}</style>', unsafe_allow_html=True)
|
10 |
+
|
11 |
+
## LOGO and TITLE
|
12 |
+
## -------------------------------------------------------------------------------------------
|
13 |
+
# Show the logo and title side by side
|
14 |
+
col1, col2 = st.columns([1, 4])
|
15 |
+
with col1:
|
16 |
+
st.image("brainbot.png", width=100)
|
17 |
+
with col2:
|
18 |
+
st.title("Image-Scan")
|
19 |
+
|
20 |
+
llm = st.session_state["llm"]
|
21 |
+
|
22 |
+
if "current_image" in st.session_state:
|
23 |
+
current_image = st.session_state['current_image']
|
24 |
+
if st.sidebar.button("Upload New Image"):
|
25 |
+
st.switch_page("BrainBot.py")
|
26 |
+
st.subheader("Your image has been uploaded successfully.")
|
27 |
+
st.success(current_image)
|
28 |
+
else:
|
29 |
+
st.warning("Upload an image to interpret it.")
|
30 |
+
if st.button("Upload Image"):
|
31 |
+
st.switch_page("BrainBot.py")
|
32 |
+
|
33 |
+
## CHAT
|
34 |
+
# Clear the image chat history if user has uploaded a new image
|
35 |
+
if st.session_state['uploaded_image'] == True:
|
36 |
+
st.session_state['image_chat_history'] = []
|
37 |
+
|
38 |
+
# Display the image chat history
|
39 |
+
for image in st.session_state['image_chat_history']:
|
40 |
+
with st.chat_message("user"):
|
41 |
+
st.image(image["path"], caption=current_image)
|
42 |
+
with st.chat_message("ai"):
|
43 |
+
st.markdown(utils.format_response(image["Description"]))
|
44 |
+
|
45 |
+
## IMAGE
|
46 |
+
# Display the image uploaded by the user
|
47 |
+
if "temp_img_path" in st.session_state and st.session_state['uploaded_image'] == True:
|
48 |
+
temp_img_path = st.session_state['temp_img_path']
|
49 |
+
with st.chat_message("human"):
|
50 |
+
st.image(temp_img_path, width=300, caption=current_image)
|
51 |
+
|
52 |
+
try:
|
53 |
+
# Send POST request to a FastAPI endpoint with temporary image path
|
54 |
+
FASTAPI_URL = f"http://localhost:8000/image/{llm}"
|
55 |
+
with st.spinner("Interpreting image..."):
|
56 |
+
response = requests.post(FASTAPI_URL, json={"image_path": temp_img_path})
|
57 |
+
# Append the image and response to the chat history
|
58 |
+
st.session_state['image_chat_history'].append({"path": temp_img_path, "Description": response.text})
|
59 |
+
st.session_state['uploaded_image'] = False
|
60 |
+
|
61 |
+
# Display the AI's interpretation of the image in chat
|
62 |
+
with st.chat_message("assistant"):
|
63 |
+
# Format the response
|
64 |
+
formatted_response = utils.format_response(response.text)
|
65 |
+
st.markdown(formatted_response)
|
66 |
+
except Exception as e:
|
67 |
+
st.switch_page("error.py")
|
Pages/pages_Web-chat.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import utils
|
4 |
+
|
5 |
+
# Custom CSS
|
6 |
+
with open('styles.css') as f:
|
7 |
+
css = f.read()
|
8 |
+
|
9 |
+
st.markdown(f'<style>{css}</style>', unsafe_allow_html=True)
|
10 |
+
|
11 |
+
## LOGO and TITLE
|
12 |
+
## -------------------------------------------------------------------------------------------
|
13 |
+
# Show the logo and title side by side
|
14 |
+
col1, col2 = st.columns([1, 4])
|
15 |
+
with col1:
|
16 |
+
st.image("brainbot.png", width=100)
|
17 |
+
with col2:
|
18 |
+
st.title("Web-Chat")
|
19 |
+
|
20 |
+
question = None
|
21 |
+
llm = st.session_state["llm"]
|
22 |
+
|
23 |
+
if "current_website" in st.session_state:
|
24 |
+
current_website = st.session_state['current_website']
|
25 |
+
if st.sidebar.button("Upload New Webpage Link"):
|
26 |
+
st.switch_page("BrainBot.py")
|
27 |
+
st.subheader("Your website content has been uploaded successfully. You can now chat with it.")
|
28 |
+
st.success(current_website)
|
29 |
+
question = st.chat_input("Type your question here...")
|
30 |
+
else:
|
31 |
+
st.warning("Upload a webpage link to begin chat with it.")
|
32 |
+
if st.button("Upload Webpage Link"):
|
33 |
+
st.switch_page("BrainBot.py")
|
34 |
+
|
35 |
+
## CHAT
|
36 |
+
# Clear the web chat history if user has uploaded a new webpage link
|
37 |
+
if st.session_state['uploaded_link'] == True:
|
38 |
+
st.session_state['web_chat_history'] = []
|
39 |
+
|
40 |
+
# Display the web chat history
|
41 |
+
for message in st.session_state['web_chat_history']:
|
42 |
+
with st.chat_message("user"):
|
43 |
+
st.write(message["Human"])
|
44 |
+
with st.chat_message("ai"):
|
45 |
+
st.markdown(utils.format_response(message["AI"]))
|
46 |
+
|
47 |
+
## QUESTION - WITH CHAT HISTORY
|
48 |
+
## -------------------------------------------------------------------------------------------
|
49 |
+
# Retrieve the answer to the question asked by the user
|
50 |
+
if question is not None:
|
51 |
+
# Display the question entered by the user in chat
|
52 |
+
with st.chat_message("user"):
|
53 |
+
st.write(question)
|
54 |
+
|
55 |
+
resource = "web"
|
56 |
+
|
57 |
+
try:
|
58 |
+
# Send POST request to a FastAPI endpoint to retrieve an answer for the question
|
59 |
+
data = {"question": question, "resource": resource}
|
60 |
+
FASTAPI_URL = f"http://localhost:8000/answer_with_chat_history/{llm}"
|
61 |
+
with st.spinner("Generating response..."):
|
62 |
+
response = requests.post(FASTAPI_URL, json=data)
|
63 |
+
# Append the response to the chat history
|
64 |
+
st.session_state['web_chat_history'].append({"Human": question, "AI": response.text})
|
65 |
+
st.session_state['uploaded_link'] = False
|
66 |
+
# Display the AI's response to the question in chat
|
67 |
+
with st.chat_message("ai"):
|
68 |
+
# Format the response
|
69 |
+
formatted_response = utils.format_response(response.text)
|
70 |
+
st.markdown(formatted_response)
|
71 |
+
except Exception as e:
|
72 |
+
st.switch_page("error.py")
|
Pages/pages_error.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
# Custom CSS
|
4 |
+
with open('styles.css') as f:
|
5 |
+
css = f.read()
|
6 |
+
|
7 |
+
st.markdown(f'<style>{css}</style>', unsafe_allow_html=True)
|
8 |
+
|
9 |
+
## LOGO and TITLE
|
10 |
+
## -------------------------------------------------------------------------------------------
|
11 |
+
# Show the logo and title side by side
|
12 |
+
col1, col2 = st.columns([1, 4])
|
13 |
+
with col1:
|
14 |
+
st.image("brainbot.png", width=100)
|
15 |
+
with col2:
|
16 |
+
st.title("Error")
|
17 |
+
|
18 |
+
st.error("Oops - Something went wrong! Please try again.")
|