aminaj commited on
Commit
7eef442
1 Parent(s): fb4987f

Update BrainBot.py

Browse files
Files changed (1) hide show
  1. BrainBot.py +22 -23
BrainBot.py CHANGED
@@ -14,19 +14,18 @@ st.markdown(f'<style>{css}</style>', unsafe_allow_html=True)
14
  ## -------------------------------------------------------------------------------------------
15
  # Function to save the uploaded file as a temporary file and return its path.
16
  def save_uploaded_file(uploaded_file):
17
- st.write("Inside func")
18
- # file_content = uploaded_file.read() # Load the document
19
- # st.write("read file")
20
- # # Create a directory if it doesn't exist
21
- # data_dir = "/data"
22
- # # os.makedirs(data_dir, exist_ok=True)
23
 
24
- # # Create a temporary file in the data directory
25
- # with tempfile.NamedTemporaryFile(delete=False, dir=data_dir) as temp_file:
26
- # st.write("writing file...")
27
- # temp_file.write(file_content) # Write the uploaded file content to the temporary file
28
- # temp_file_path = temp_file.name # Get the path of the temporary file
29
- # return temp_file_path
30
 
31
  # Function to save the uploaded image as a temporary file and return its path.
32
  def save_uploaded_image(uploaded_image):
@@ -130,17 +129,17 @@ if uploaded_file is not None:
130
  temp_file_path = save_uploaded_file(uploaded_file)
131
  st.write(temp_file_path)
132
 
133
- # try:
134
- # # Send POST request to a FastAPI endpoint to load the file into a vectorstore
135
- # data = {"file_path": temp_file_path, "file_type": uploaded_file.type}
136
- # FASTAPI_URL = f"http://localhost:7860/load_file/{llm}"
137
- # response = requests.post(FASTAPI_URL, json=data)
138
- # st.success(response.text)
139
- # st.session_state['current_file'] = uploaded_file.name
140
- # st.session_state['uploaded_file'] = True
141
- # st.switch_page("pages/File-chat.py")
142
- # except Exception as e:
143
- # st.switch_page("pages/error.py")
144
 
145
  ## IMAGE
146
  ## -------------------------------------------------------------------------------------------
 
14
  ## -------------------------------------------------------------------------------------------
15
  # Function to save the uploaded file as a temporary file and return its path.
16
  def save_uploaded_file(uploaded_file):
17
+ file_content = uploaded_file.read() # Load the document
18
+ st.write("read file")
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
24
+ with tempfile.NamedTemporaryFile(delete=False, dir=data_dir) as temp_file:
25
+ st.write("writing file...")
26
+ temp_file.write(file_content) # Write the uploaded file content to the temporary file
27
+ temp_file_path = temp_file.name # Get the path of the temporary file
28
+ return temp_file_path
29
 
30
  # Function to save the uploaded image as a temporary file and return its path.
31
  def save_uploaded_image(uploaded_image):
 
129
  temp_file_path = save_uploaded_file(uploaded_file)
130
  st.write(temp_file_path)
131
 
132
+ try:
133
+ # Send POST request to a FastAPI endpoint to load the file into a vectorstore
134
+ data = {"file_path": temp_file_path, "file_type": uploaded_file.type}
135
+ FASTAPI_URL = f"http://localhost:7860/load_file/{llm}"
136
+ response = requests.post(FASTAPI_URL, json=data)
137
+ st.success(response.text)
138
+ st.session_state['current_file'] = uploaded_file.name
139
+ st.session_state['uploaded_file'] = True
140
+ st.switch_page("pages/File-chat.py")
141
+ except Exception as e:
142
+ st.switch_page("pages/error.py")
143
 
144
  ## IMAGE
145
  ## -------------------------------------------------------------------------------------------