TahaRasouli commited on
Commit
a942df2
Β·
verified Β·
1 Parent(s): b658c92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -18
app.py CHANGED
@@ -161,9 +161,11 @@ class StreamlitDocProcessor:
161
  for file in sorted(st.session_state.processed_files['pdf']):
162
  st.text(f"πŸ“„ {file}")
163
 
 
 
164
  def qa_page(self):
165
  st.header("Query Documents")
166
-
167
  try:
168
  # Refresh available files
169
  st.session_state.processed_files = self.get_processed_files()
@@ -171,45 +173,100 @@ class StreamlitDocProcessor:
171
  if not any(st.session_state.processed_files.values()):
172
  st.warning("No processed files available. Please upload and process some files first.")
173
  return
174
-
175
  # Create combined list of files with icons
176
  all_files = []
177
  for file in st.session_state.processed_files.get('xml', []):
178
  all_files.append(f"πŸ“± {file}")
179
  for file in st.session_state.processed_files.get('pdf', []):
180
  all_files.append(f"πŸ“„ {file}")
181
-
182
  if not all_files:
183
  st.warning("No processed files available. Please upload and process some files first.")
184
  return
185
-
186
  # File selection
187
  selected_files = st.multiselect(
188
  "Select files to search through",
189
  sorted(all_files),
190
  default=all_files
191
  )
192
-
193
  # Remove icons from selected files
194
  selected_files = [f.split(' ', 1)[1] for f in selected_files]
195
-
196
  if not selected_files:
197
  st.warning("Please select at least one file to search through.")
198
  return
199
 
200
- # Question input
201
- question = st.text_input("Enter your question:")
 
 
 
202
 
203
- if st.button("Ask Question") and question:
204
- try:
205
- with st.spinner("Searching for answer..."):
206
- answer = st.session_state.processor.ask_question_selective(
207
- question,
208
- selected_files
209
- )
210
- st.write("Answer:", answer)
211
- except Exception as e:
212
- st.error(f"Error getting answer: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
 
214
  except Exception as e:
215
  st.error(f"Error in Q&A interface: {str(e)}")
 
161
  for file in sorted(st.session_state.processed_files['pdf']):
162
  st.text(f"πŸ“„ {file}")
163
 
164
+ # Modify the qa_page method in the StreamlitDocProcessor class
165
+
166
  def qa_page(self):
167
  st.header("Query Documents")
168
+
169
  try:
170
  # Refresh available files
171
  st.session_state.processed_files = self.get_processed_files()
 
173
  if not any(st.session_state.processed_files.values()):
174
  st.warning("No processed files available. Please upload and process some files first.")
175
  return
176
+
177
  # Create combined list of files with icons
178
  all_files = []
179
  for file in st.session_state.processed_files.get('xml', []):
180
  all_files.append(f"πŸ“± {file}")
181
  for file in st.session_state.processed_files.get('pdf', []):
182
  all_files.append(f"πŸ“„ {file}")
183
+
184
  if not all_files:
185
  st.warning("No processed files available. Please upload and process some files first.")
186
  return
187
+
188
  # File selection
189
  selected_files = st.multiselect(
190
  "Select files to search through",
191
  sorted(all_files),
192
  default=all_files
193
  )
194
+
195
  # Remove icons from selected files
196
  selected_files = [f.split(' ', 1)[1] for f in selected_files]
197
+
198
  if not selected_files:
199
  st.warning("Please select at least one file to search through.")
200
  return
201
 
202
+ # Question input
203
+ question = st.text_input("Enter your question:")
204
+
205
+ if question:
206
+ col1, col2, col3 = st.columns(3)
207
 
208
+ with col1:
209
+ if st.button("Quick Answer"):
210
+ try:
211
+ with st.spinner("Getting quick answer..."):
212
+ answer = st.session_state.processor.ask_question_selective(
213
+ question,
214
+ selected_files
215
+ )
216
+ st.write("Answer:", answer)
217
+ except Exception as e:
218
+ st.error(f"Error getting answer: {str(e)}")
219
+
220
+ with col2:
221
+ if st.button("Detailed Answer"):
222
+ try:
223
+ with st.spinner("Getting detailed answer..."):
224
+ result = st.session_state.processor.get_detailed_context(
225
+ question,
226
+ selected_files
227
+ )
228
+ if result['success']:
229
+ st.write("### Relevant Information")
230
+ for item in result['results']:
231
+ with st.expander(f"Source: {item['metadata']['source_file']} ({item['metadata']['content_type'].upper()})"):
232
+ st.write(f"Relevance Score: {item['relevance_score']:.2f}")
233
+ if item['metadata']['content_type'] == 'xml':
234
+ st.write(f"XML Path: {item['source_info']['path']}")
235
+ st.write("Content:", item['content'])
236
+ else:
237
+ st.error(result['error'])
238
+ except Exception as e:
239
+ st.error(f"Error getting detailed answer: {str(e)}")
240
+
241
+ with col3:
242
+ if st.button("Complete Analysis"):
243
+ try:
244
+ with st.spinner("Performing complete analysis..."):
245
+ result = st.session_state.processor.get_summary_and_details(
246
+ question,
247
+ selected_files
248
+ )
249
+ if result['success']:
250
+ st.write("### Summary")
251
+ st.write(result['summary'])
252
+
253
+ st.write("### Detailed Information")
254
+ for item in result['details']:
255
+ with st.expander(f"Source: {item['metadata']['source_file']} ({item['metadata']['content_type'].upper()})"):
256
+ st.write(f"Relevance Score: {item['relevance_score']:.2f}")
257
+ if item['metadata']['content_type'] == 'xml':
258
+ st.write(f"XML Path: {item['source_info']['path']}")
259
+ if 'parent_info' in item:
260
+ st.write("Parent Element:", item['parent_info']['content'])
261
+ if 'children_info' in item:
262
+ st.write("Related Elements:")
263
+ for child in item['children_info']:
264
+ st.write(f"- {child['content']}")
265
+ st.write("Content:", item['content'])
266
+ else:
267
+ st.error(result['error'])
268
+ except Exception as e:
269
+ st.error(f"Error getting complete analysis: {str(e)}")
270
 
271
  except Exception as e:
272
  st.error(f"Error in Q&A interface: {str(e)}")