Ali2206 commited on
Commit
2f7b7e0
·
verified ·
1 Parent(s): 7aa0939

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -227,7 +227,7 @@ Avoid repeating the same points multiple times.
227
  def remove_non_ascii(text):
228
  return unicodedata.normalize('NFKD', text).encode('ascii', 'ignore').decode('ascii')
229
 
230
- def generate_pdf_report_with_charts(summary: str, report_path: str):
231
  chart_dir = os.path.join(os.path.dirname(report_path), "charts")
232
  os.makedirs(chart_dir, exist_ok=True)
233
 
@@ -254,6 +254,19 @@ def generate_pdf_report_with_charts(summary: str, report_path: str):
254
 
255
  pdf.ln(10)
256
  pdf.image(chart_path, w=150)
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  pdf.output(pdf_path)
258
  return pdf_path
259
 
@@ -288,7 +301,7 @@ def process_report(agent, file, messages: List[Dict[str, str]]) -> Tuple[List[Di
288
  with open(report_path, 'w', encoding='utf-8') as f:
289
  f.write(f"# Final Medical Report\n\n{summary}")
290
 
291
- pdf_path = generate_pdf_report_with_charts(summary, report_path)
292
 
293
  end_time = time.time()
294
  elapsed_time = end_time - start_time
@@ -334,4 +347,5 @@ def create_ui(agent):
334
  if __name__ == "__main__":
335
  agent = init_agent()
336
  ui = create_ui(agent)
337
- ui.launch(server_name="0.0.0.0", server_port=7860, allowed_paths=["/data/hf_cache/reports"], share=False)
 
 
227
  def remove_non_ascii(text):
228
  return unicodedata.normalize('NFKD', text).encode('ascii', 'ignore').decode('ascii')
229
 
230
+ def generate_pdf_report_with_charts(summary: str, report_path: str, detailed_batches: List[str] = None):
231
  chart_dir = os.path.join(os.path.dirname(report_path), "charts")
232
  os.makedirs(chart_dir, exist_ok=True)
233
 
 
254
 
255
  pdf.ln(10)
256
  pdf.image(chart_path, w=150)
257
+
258
+ # Add detailed outputs per batch/tool
259
+ if detailed_batches:
260
+ pdf.add_page()
261
+ pdf.set_font("Arial", size=12)
262
+ pdf.multi_cell(0, 10, txt="Detailed Analysis Per Tool", align="L")
263
+ pdf.ln(5)
264
+ for idx, detail in enumerate(detailed_batches):
265
+ pdf.multi_cell(0, 10, txt=f"Tool Result #{idx + 1}", align="L")
266
+ for line in remove_non_ascii(detail).split("
267
+ "):
268
+ pdf.multi_cell(0, 10, txt=line)
269
+ pdf.ln(5)
270
  pdf.output(pdf_path)
271
  return pdf_path
272
 
 
301
  with open(report_path, 'w', encoding='utf-8') as f:
302
  f.write(f"# Final Medical Report\n\n{summary}")
303
 
304
+ pdf_path = generate_pdf_report_with_charts(summary, report_path, detailed_batches=valid)
305
 
306
  end_time = time.time()
307
  elapsed_time = end_time - start_time
 
347
  if __name__ == "__main__":
348
  agent = init_agent()
349
  ui = create_ui(agent)
350
+ ui.launch(server_name="0.0.0.0", server_port=7860, allowed_paths=["/data/hf_cache/reports"], share=False)
351
+