Update app.py
Browse files
app.py
CHANGED
@@ -188,8 +188,10 @@ def generate_final_summary(agent, combined: str) -> str:
|
|
188 |
combined = remove_duplicate_paragraphs(combined)
|
189 |
final_prompt = f"""
|
190 |
You are an expert clinical summarizer. Analyze the following summaries carefully and generate a **single final concise structured medical report**, avoiding any repetition or redundancy.
|
|
|
191 |
Summaries:
|
192 |
{combined}
|
|
|
193 |
Respond with:
|
194 |
- Diagnostic Patterns
|
195 |
- Medication Issues
|
@@ -227,6 +229,7 @@ def process_report(agent, file, messages: List[Dict[str, str]]) -> Tuple[List[Di
|
|
227 |
messages.append({"role": "assistant", "content": "β Please upload a valid file."})
|
228 |
return messages, None
|
229 |
|
|
|
230 |
messages.append({"role": "user", "content": f"π Processing file: {os.path.basename(file.name)}"})
|
231 |
try:
|
232 |
extracted = extract_text(file.name)
|
@@ -246,18 +249,24 @@ def process_report(agent, file, messages: List[Dict[str, str]]) -> Tuple[List[Di
|
|
246 |
return messages, None
|
247 |
|
248 |
summary = generate_final_summary(agent, "\n\n".join(valid))
|
|
|
249 |
report_path = os.path.join(report_dir, f"report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md")
|
250 |
with open(report_path, 'w', encoding='utf-8') as f:
|
251 |
f.write(f"# π§ Final Medical Report\n\n{summary}")
|
252 |
|
253 |
-
|
254 |
-
|
|
|
|
|
|
|
|
|
255 |
return messages, report_path
|
256 |
|
257 |
except Exception as e:
|
258 |
messages.append({"role": "assistant", "content": f"β Error: {str(e)}"})
|
259 |
return messages, None
|
260 |
|
|
|
261 |
def create_ui(agent):
|
262 |
with gr.Blocks(css="""
|
263 |
html, body, .gradio-container { background: #0e1621; color: #e0e0e0; padding: 16px; }
|
|
|
188 |
combined = remove_duplicate_paragraphs(combined)
|
189 |
final_prompt = f"""
|
190 |
You are an expert clinical summarizer. Analyze the following summaries carefully and generate a **single final concise structured medical report**, avoiding any repetition or redundancy.
|
191 |
+
|
192 |
Summaries:
|
193 |
{combined}
|
194 |
+
|
195 |
Respond with:
|
196 |
- Diagnostic Patterns
|
197 |
- Medication Issues
|
|
|
229 |
messages.append({"role": "assistant", "content": "β Please upload a valid file."})
|
230 |
return messages, None
|
231 |
|
232 |
+
start_time = time.time() # Start timing here
|
233 |
messages.append({"role": "user", "content": f"π Processing file: {os.path.basename(file.name)}"})
|
234 |
try:
|
235 |
extracted = extract_text(file.name)
|
|
|
249 |
return messages, None
|
250 |
|
251 |
summary = generate_final_summary(agent, "\n\n".join(valid))
|
252 |
+
|
253 |
report_path = os.path.join(report_dir, f"report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md")
|
254 |
with open(report_path, 'w', encoding='utf-8') as f:
|
255 |
f.write(f"# π§ Final Medical Report\n\n{summary}")
|
256 |
|
257 |
+
end_time = time.time()
|
258 |
+
elapsed_time = end_time - start_time
|
259 |
+
|
260 |
+
print(f"β
Total processing time: {elapsed_time:.2f} seconds") # Print the time
|
261 |
+
|
262 |
+
messages.append({"role": "assistant", "content": f"π Final Report generated in **{elapsed_time:.2f} seconds**.\n\nβ
Report saved: {os.path.basename(report_path)}"})
|
263 |
return messages, report_path
|
264 |
|
265 |
except Exception as e:
|
266 |
messages.append({"role": "assistant", "content": f"β Error: {str(e)}"})
|
267 |
return messages, None
|
268 |
|
269 |
+
|
270 |
def create_ui(agent):
|
271 |
with gr.Blocks(css="""
|
272 |
html, body, .gradio-container { background: #0e1621; color: #e0e0e0; padding: 16px; }
|