Update BrainBot.py
Browse files- BrainBot.py +5 -18
BrainBot.py
CHANGED
|
@@ -8,19 +8,7 @@ import os
|
|
| 8 |
with open('styles.css') as f:
|
| 9 |
css = f.read()
|
| 10 |
|
| 11 |
-
st.markdown(f'<style>{css}</style>', unsafe_allow_html=True)
|
| 12 |
-
|
| 13 |
-
## SERVER SETUP
|
| 14 |
-
## -------------------------------------------------------------------------------------------
|
| 15 |
-
# def start_server():
|
| 16 |
-
# os.system("uvicorn main:app --port 7860 --host 0.0.0.0 --workers 2")
|
| 17 |
-
# st.session_state['server_started'] = True
|
| 18 |
-
|
| 19 |
-
# if 'server_started' not in st.session_state:
|
| 20 |
-
# st.session_state['server_started'] = False
|
| 21 |
-
|
| 22 |
-
# if not st.session_state['server_started']:
|
| 23 |
-
# start_server()
|
| 24 |
|
| 25 |
## FUNCTIONS
|
| 26 |
## -------------------------------------------------------------------------------------------
|
|
@@ -29,7 +17,7 @@ def save_uploaded_file(uploaded_file):
|
|
| 29 |
file_content = uploaded_file.read() # Load the document
|
| 30 |
|
| 31 |
# Create a directory if it doesn't exist
|
| 32 |
-
data_dir = "data"
|
| 33 |
# os.makedirs(data_dir, exist_ok=True)
|
| 34 |
|
| 35 |
# Create a temporary file in the data directory
|
|
@@ -93,14 +81,13 @@ with col3:
|
|
| 93 |
# variable
|
| 94 |
with st.spinner("Activating OpenAI API..."):
|
| 95 |
try:
|
| 96 |
-
# FASTAPI_URL = "http://localhost:8000/set_api_key"
|
| 97 |
FASTAPI_URL = "http://localhost:7860/set_api_key"
|
| 98 |
data = {"api_key": openai_api_key}
|
| 99 |
if openai_api_key:
|
| 100 |
response = requests.post(FASTAPI_URL, json=data)
|
| 101 |
st.sidebar.success(response.text)
|
| 102 |
st.session_state['api_key_flag'] = True
|
| 103 |
-
|
| 104 |
except Exception as e:
|
| 105 |
st.switch_page("pages/error.py")
|
| 106 |
with col4:
|
|
@@ -143,7 +130,7 @@ if uploaded_file is not None:
|
|
| 143 |
try:
|
| 144 |
# Send POST request to a FastAPI endpoint to load the file into a vectorstore
|
| 145 |
data = {"file_path": temp_file_path, "file_type": uploaded_file.type}
|
| 146 |
-
FASTAPI_URL = f"http://localhost:
|
| 147 |
st.write(FASTAPI_URL)
|
| 148 |
response = requests.post(FASTAPI_URL, json=data)
|
| 149 |
st.success(response.text)
|
|
@@ -181,7 +168,7 @@ if website_link is not None:
|
|
| 181 |
try:
|
| 182 |
# Send POST request to a FastAPI endpoint to scrape the webpage and load its text
|
| 183 |
# into a vector store
|
| 184 |
-
FASTAPI_URL = f"http://localhost:
|
| 185 |
data = {"website_link": website_link}
|
| 186 |
with st.spinner("Loading website..."):
|
| 187 |
response = requests.post(FASTAPI_URL, json=data)
|
|
|
|
| 8 |
with open('styles.css') as f:
|
| 9 |
css = f.read()
|
| 10 |
|
| 11 |
+
st.markdown(f'<style>{css}</style>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
## FUNCTIONS
|
| 14 |
## -------------------------------------------------------------------------------------------
|
|
|
|
| 17 |
file_content = uploaded_file.read() # Load the document
|
| 18 |
|
| 19 |
# Create a directory if it doesn't exist
|
| 20 |
+
data_dir = "/data"
|
| 21 |
# os.makedirs(data_dir, exist_ok=True)
|
| 22 |
|
| 23 |
# Create a temporary file in the data directory
|
|
|
|
| 81 |
# variable
|
| 82 |
with st.spinner("Activating OpenAI API..."):
|
| 83 |
try:
|
|
|
|
| 84 |
FASTAPI_URL = "http://localhost:7860/set_api_key"
|
| 85 |
data = {"api_key": openai_api_key}
|
| 86 |
if openai_api_key:
|
| 87 |
response = requests.post(FASTAPI_URL, json=data)
|
| 88 |
st.sidebar.success(response.text)
|
| 89 |
st.session_state['api_key_flag'] = True
|
| 90 |
+
st.experimental_rerun()
|
| 91 |
except Exception as e:
|
| 92 |
st.switch_page("pages/error.py")
|
| 93 |
with col4:
|
|
|
|
| 130 |
try:
|
| 131 |
# Send POST request to a FastAPI endpoint to load the file into a vectorstore
|
| 132 |
data = {"file_path": temp_file_path, "file_type": uploaded_file.type}
|
| 133 |
+
FASTAPI_URL = f"http://localhost:7860/load_file/{llm}"
|
| 134 |
st.write(FASTAPI_URL)
|
| 135 |
response = requests.post(FASTAPI_URL, json=data)
|
| 136 |
st.success(response.text)
|
|
|
|
| 168 |
try:
|
| 169 |
# Send POST request to a FastAPI endpoint to scrape the webpage and load its text
|
| 170 |
# into a vector store
|
| 171 |
+
FASTAPI_URL = f"http://localhost:7860/load_link/{llm}"
|
| 172 |
data = {"website_link": website_link}
|
| 173 |
with st.spinner("Loading website..."):
|
| 174 |
response = requests.post(FASTAPI_URL, json=data)
|