Ali2206 commited on
Commit
64b615d
·
verified ·
1 Parent(s): 1a91307

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -224,9 +224,16 @@ Avoid repeating the same points multiple times.
224
  return final_response
225
 
226
  def generate_pdf_report_with_charts(summary: str, report_path: str):
 
 
 
 
 
 
227
  chart_dir = os.path.join(os.path.dirname(report_path), "charts")
228
  os.makedirs(chart_dir, exist_ok=True)
229
 
 
230
  chart_path = os.path.join(chart_dir, "summary_chart.png")
231
  categories = ['Diagnostics', 'Medications', 'Missed', 'Inconsistencies', 'Follow-up']
232
  values = [4, 2, 3, 1, 5]
@@ -237,14 +244,17 @@ def generate_pdf_report_with_charts(summary: str, report_path: str):
237
  plt.savefig(chart_path)
238
  plt.close()
239
 
 
240
  pdf_path = report_path.replace('.md', '.pdf')
241
  pdf = FPDF()
242
  pdf.add_page()
243
  pdf.set_font("Arial", size=12)
244
  pdf.multi_cell(0, 10, txt="Final Medical Report", align="C")
245
  pdf.ln(5)
 
246
  for line in summary.split("\n"):
247
- pdf.multi_cell(0, 10, txt=line)
 
248
  pdf.ln(10)
249
  pdf.image(chart_path, w=150)
250
  pdf.output(pdf_path)
 
224
  return final_response
225
 
226
  def generate_pdf_report_with_charts(summary: str, report_path: str):
227
+ import unicodedata
228
+
229
+ def clean_for_pdf(text):
230
+ # Remove emojis and any non-latin characters
231
+ return ''.join(c for c in text if unicodedata.category(c)[0] != 'So')
232
+
233
  chart_dir = os.path.join(os.path.dirname(report_path), "charts")
234
  os.makedirs(chart_dir, exist_ok=True)
235
 
236
+ # Dummy chart
237
  chart_path = os.path.join(chart_dir, "summary_chart.png")
238
  categories = ['Diagnostics', 'Medications', 'Missed', 'Inconsistencies', 'Follow-up']
239
  values = [4, 2, 3, 1, 5]
 
244
  plt.savefig(chart_path)
245
  plt.close()
246
 
247
+ # PDF report
248
  pdf_path = report_path.replace('.md', '.pdf')
249
  pdf = FPDF()
250
  pdf.add_page()
251
  pdf.set_font("Arial", size=12)
252
  pdf.multi_cell(0, 10, txt="Final Medical Report", align="C")
253
  pdf.ln(5)
254
+
255
  for line in summary.split("\n"):
256
+ pdf.multi_cell(0, 10, txt=clean_for_pdf(line))
257
+
258
  pdf.ln(10)
259
  pdf.image(chart_path, w=150)
260
  pdf.output(pdf_path)