Ali2206 commited on
Commit
7fd42f9
·
verified ·
1 Parent(s): c5138bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -6
app.py CHANGED
@@ -231,31 +231,56 @@ def generate_pdf_report_with_charts(summary: str, report_path: str, detailed_bat
231
  chart_dir = os.path.join(os.path.dirname(report_path), "charts")
232
  os.makedirs(chart_dir, exist_ok=True)
233
 
234
- chart_path = os.path.join(chart_dir, "summary_chart.png")
 
235
  categories = ['Diagnostics', 'Medications', 'Missed', 'Inconsistencies', 'Follow-up']
236
  values = [4, 2, 3, 1, 5]
237
  plt.figure(figsize=(6, 4))
238
  plt.bar(categories, values)
239
  plt.title('Clinical Issues Overview')
240
  plt.tight_layout()
241
- plt.savefig(chart_path)
242
  plt.close()
243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  pdf_path = report_path.replace('.md', '.pdf')
245
  pdf = FPDF()
246
  pdf.add_page()
247
  pdf.set_font("Arial", size=12)
248
  pdf.multi_cell(0, 10, txt="Final Medical Report", align="C")
249
  pdf.ln(5)
250
-
251
  for line in summary.split("\n"):
252
  clean_line = remove_non_ascii(line)
253
  pdf.multi_cell(0, 10, txt=clean_line)
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)
@@ -264,9 +289,9 @@ def generate_pdf_report_with_charts(summary: str, report_path: str, detailed_bat
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("\n"):
267
-
268
  pdf.multi_cell(0, 10, txt=line)
269
  pdf.ln(5)
 
270
  pdf.output(pdf_path)
271
  return pdf_path
272
 
 
231
  chart_dir = os.path.join(os.path.dirname(report_path), "charts")
232
  os.makedirs(chart_dir, exist_ok=True)
233
 
234
+ # Bar chart
235
+ bar_chart_path = os.path.join(chart_dir, "summary_chart.png")
236
  categories = ['Diagnostics', 'Medications', 'Missed', 'Inconsistencies', 'Follow-up']
237
  values = [4, 2, 3, 1, 5]
238
  plt.figure(figsize=(6, 4))
239
  plt.bar(categories, values)
240
  plt.title('Clinical Issues Overview')
241
  plt.tight_layout()
242
+ plt.savefig(bar_chart_path)
243
  plt.close()
244
 
245
+ # Pie chart
246
+ pie_chart_path = os.path.join(chart_dir, "summary_pie_chart.png")
247
+ plt.figure(figsize=(6, 6))
248
+ plt.pie(values, labels=categories, autopct='%1.1f%%', startangle=140)
249
+ plt.title('Distribution of Clinical Issues')
250
+ plt.tight_layout()
251
+ plt.savefig(pie_chart_path)
252
+ plt.close()
253
+
254
+ # Line graph
255
+ line_chart_path = os.path.join(chart_dir, "trend_chart.png")
256
+ plt.figure(figsize=(6, 4))
257
+ plt.plot(categories, values, marker='o')
258
+ plt.title('Clinical Concern Trend')
259
+ plt.xlabel('Category')
260
+ plt.ylabel('Concern Level')
261
+ plt.tight_layout()
262
+ plt.savefig(line_chart_path)
263
+ plt.close()
264
+
265
+ # PDF Creation
266
  pdf_path = report_path.replace('.md', '.pdf')
267
  pdf = FPDF()
268
  pdf.add_page()
269
  pdf.set_font("Arial", size=12)
270
  pdf.multi_cell(0, 10, txt="Final Medical Report", align="C")
271
  pdf.ln(5)
 
272
  for line in summary.split("\n"):
273
  clean_line = remove_non_ascii(line)
274
  pdf.multi_cell(0, 10, txt=clean_line)
275
 
276
  pdf.ln(10)
277
+ pdf.image(bar_chart_path, w=150)
278
+ pdf.ln(5)
279
+ pdf.image(pie_chart_path, w=150)
280
+ pdf.ln(5)
281
+ pdf.image(line_chart_path, w=150)
282
 
283
+ # Detailed batch results
284
  if detailed_batches:
285
  pdf.add_page()
286
  pdf.set_font("Arial", size=12)
 
289
  for idx, detail in enumerate(detailed_batches):
290
  pdf.multi_cell(0, 10, txt=f"Tool Result #{idx + 1}", align="L")
291
  for line in remove_non_ascii(detail).split("\n"):
 
292
  pdf.multi_cell(0, 10, txt=line)
293
  pdf.ln(5)
294
+
295
  pdf.output(pdf_path)
296
  return pdf_path
297