Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
-
|
|
|
|
|
2 |
import pdfplumber
|
3 |
import json
|
4 |
import gradio as gr
|
5 |
-
from typing import List
|
6 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
7 |
import hashlib
|
8 |
import shutil
|
@@ -168,14 +170,18 @@ def format_response_for_ui(response: str) -> str:
|
|
168 |
return "\n".join(formatted)
|
169 |
return cleaned
|
170 |
|
171 |
-
def analyze(message: str, history:
|
172 |
start_time = datetime.now()
|
173 |
logger.info(f"Starting analysis for message: {message[:100]}...")
|
174 |
if files:
|
175 |
logger.info(f"Processing {len(files)} uploaded files")
|
176 |
|
177 |
-
|
178 |
-
|
|
|
|
|
|
|
|
|
179 |
yield history, None
|
180 |
|
181 |
extracted = ""
|
@@ -190,7 +196,7 @@ def analyze(message: str, history: list, files: list):
|
|
190 |
logger.info(f"Processed {len(files)} files, extracted {len(extracted)} characters")
|
191 |
except Exception as e:
|
192 |
logger.error(f"Error processing files: {str(e)}")
|
193 |
-
history[-1] =
|
194 |
yield history, None
|
195 |
return
|
196 |
|
@@ -230,7 +236,7 @@ Medical Records:
|
|
230 |
formatted_partial = format_response_for_ui(partial_response)
|
231 |
|
232 |
if formatted_partial:
|
233 |
-
history[-1] =
|
234 |
yield history, None
|
235 |
|
236 |
full_response = "".join(response_chunks)
|
@@ -241,7 +247,7 @@ Medical Records:
|
|
241 |
final_output = "No clear oversights identified. Recommend comprehensive review."
|
242 |
logger.info("No significant findings detected in analysis")
|
243 |
|
244 |
-
history[-1] =
|
245 |
|
246 |
# Save report
|
247 |
report_path = None
|
@@ -260,7 +266,7 @@ Medical Records:
|
|
260 |
|
261 |
except Exception as e:
|
262 |
logger.error(f"Error during analysis: {str(e)}", exc_info=True)
|
263 |
-
history[-1] =
|
264 |
yield history, None
|
265 |
|
266 |
def create_ui(agent):
|
|
|
1 |
+
import sys
|
2 |
+
import os
|
3 |
+
import pandas as pd
|
4 |
import pdfplumber
|
5 |
import json
|
6 |
import gradio as gr
|
7 |
+
from typing import List, Tuple
|
8 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
9 |
import hashlib
|
10 |
import shutil
|
|
|
170 |
return "\n".join(formatted)
|
171 |
return cleaned
|
172 |
|
173 |
+
def analyze(message: str, history: List[Tuple[str, str]], files: list):
|
174 |
start_time = datetime.now()
|
175 |
logger.info(f"Starting analysis for message: {message[:100]}...")
|
176 |
if files:
|
177 |
logger.info(f"Processing {len(files)} uploaded files")
|
178 |
|
179 |
+
# Initialize chat history in the correct format if empty
|
180 |
+
if history is None:
|
181 |
+
history = []
|
182 |
+
|
183 |
+
# Add user message to history
|
184 |
+
history.append([message, None])
|
185 |
yield history, None
|
186 |
|
187 |
extracted = ""
|
|
|
196 |
logger.info(f"Processed {len(files)} files, extracted {len(extracted)} characters")
|
197 |
except Exception as e:
|
198 |
logger.error(f"Error processing files: {str(e)}")
|
199 |
+
history[-1][1] = f"❌ Error processing files: {str(e)}"
|
200 |
yield history, None
|
201 |
return
|
202 |
|
|
|
236 |
formatted_partial = format_response_for_ui(partial_response)
|
237 |
|
238 |
if formatted_partial:
|
239 |
+
history[-1][1] = formatted_partial
|
240 |
yield history, None
|
241 |
|
242 |
full_response = "".join(response_chunks)
|
|
|
247 |
final_output = "No clear oversights identified. Recommend comprehensive review."
|
248 |
logger.info("No significant findings detected in analysis")
|
249 |
|
250 |
+
history[-1][1] = final_output
|
251 |
|
252 |
# Save report
|
253 |
report_path = None
|
|
|
266 |
|
267 |
except Exception as e:
|
268 |
logger.error(f"Error during analysis: {str(e)}", exc_info=True)
|
269 |
+
history[-1][1] = f"❌ Error during analysis: {str(e)}"
|
270 |
yield history, None
|
271 |
|
272 |
def create_ui(agent):
|