aneesqumar commited on
Commit
d7bc893
·
verified ·
1 Parent(s): 8407aa8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -86
app.py CHANGED
@@ -51,7 +51,8 @@ Preventative Measures
51
  Follow-up Recommendations
52
 
53
  Keep headings clear.
54
- End with reminder to consult qualified doctor.
 
55
  """
56
 
57
  response = client.chat.completions.create(
@@ -240,83 +241,6 @@ Medication: {d['medication']}
240
  # ===============================
241
  # PDF GENERATION
242
  # ===============================
243
- '''def generate_pdf(*inputs):
244
-
245
- global last_basic_data, last_llm_report
246
-
247
- d = last_basic_data
248
- file_path = f"{d['name']}_Typhoid_Report.pdf"
249
- doc = SimpleDocTemplate(file_path)
250
- elements = []
251
- styles = getSampleStyleSheet()
252
-
253
- # ---- LOGO ----
254
- if os.path.exists(LOGO_PATH):
255
- elements.append(Image(LOGO_PATH, width=1.5*inch, height=1.5*inch))
256
- elements.append(Spacer(1,0.2*inch))
257
-
258
- elements.append(Paragraph("<b>TyphoidGuard AI Clinical Report</b>", styles["Title"]))
259
- elements.append(Spacer(1, 0.3 * inch))
260
-
261
- # ---- RISK BADGE ----
262
- risk_color = colors.HexColor(d["color"])
263
- badge_style = ParagraphStyle(
264
- name="Badge",
265
- parent=styles["Normal"],
266
- backColor=risk_color,
267
- textColor=colors.white,
268
- fontSize=12,
269
- leftIndent=5,
270
- rightIndent=5,
271
- spaceAfter=10
272
- )
273
-
274
- elements.append(Paragraph(
275
- f"Risk: {d['prob_pct']}% - {d['risk_label']}",
276
- badge_style
277
- ))
278
- elements.append(Spacer(1,0.3*inch))
279
-
280
- table_data = [
281
- ["Patient Name", d["name"]],
282
- ["Age", d["age"]],
283
- ["Gender", d["gender"]],
284
- ["Platelet Count", d["platelets"]],
285
- ["Hemoglobin", d["hb"]],
286
- ["Treatment Duration", d["duration"]],
287
- ["Bacteria", d["bacteria"]],
288
- ["Severity", d["severity"]],
289
- ["Medication", d["medication"]],
290
- ]
291
-
292
- table = Table(table_data, colWidths=[2.5*inch, 3*inch])
293
- table.setStyle(TableStyle([
294
- ('GRID',(0,0),(-1,-1),1,colors.grey),
295
- ('FONTNAME',(0,0),(-1,-1),'Helvetica')
296
- ]))
297
-
298
- elements.append(table)
299
- elements.append(Spacer(1,0.4*inch))
300
-
301
- elements.append(Paragraph("<b>Agent Recommendation</b>", styles["Heading2"]))
302
- elements.append(Paragraph(d["recommendation"], styles["Normal"]))
303
- elements.append(Spacer(1,0.4*inch))
304
-
305
- if last_llm_report:
306
- elements.append(Paragraph("<b>Detailed AI Report</b>", styles["Heading2"]))
307
- elements.append(Paragraph(last_llm_report.replace("\n","<br/>"), styles["Normal"]))
308
-
309
- elements.append(Spacer(1,0.5*inch))
310
- elements.append(Paragraph("<b>Team Chinar AI (AJK)</b>", styles["Normal"]))
311
- elements.append(Paragraph(
312
- "Anees Qumar Abbasi | Sharafat Hussain | Salma Asghar | "
313
- "Kaleem Hussain | Munazza Zahra | Kokub Khurishid",
314
- styles["Normal"]
315
- ))
316
-
317
- doc.build(elements)
318
- return file_path
319
- '''
320
  def generate_pdf(*inputs):
321
 
322
  global last_basic_data, last_llm_report
@@ -415,9 +339,7 @@ def generate_pdf(*inputs):
415
  elements.append(Paragraph(d["recommendation"], styles["Normal"]))
416
  elements.append(Spacer(1,0.4*inch))
417
 
418
- # ---- DETAILED AI REPORT (Formatted with Headings + Bullets) ----
419
- # ---- DETAILED AI REPORT (Formatted with ## Headings) ----
420
-
421
  if last_llm_report:
422
  elements.append(Paragraph("<b>Detailed AI Report</b>", heading_style))
423
  elements.append(Spacer(1,0.2*inch))
@@ -430,11 +352,9 @@ def generate_pdf(*inputs):
430
  if not line:
431
  continue
432
 
433
- # ❌ Remove disclaimer coming from LLM
434
  if "consult a qualified doctor" in line.lower():
435
  continue
436
 
437
- # ✅ Detect headings starting with ##
438
  if line.startswith("##"):
439
  clean_heading = line.replace("##", "").strip()
440
  elements.append(Spacer(1,0.2*inch))
@@ -443,7 +363,6 @@ def generate_pdf(*inputs):
443
  )
444
  else:
445
  elements.append(Paragraph(line, styles["Normal"]))
446
- #elements.append(Paragraph(f"• {line}", bullet_style))
447
 
448
  elements.append(Spacer(1,0.5*inch))
449
 
@@ -462,13 +381,17 @@ def generate_pdf(*inputs):
462
  elements.append(Paragraph("<b>Team Chinar AI (AJK)</b>", styles["Normal"]))
463
  elements.append(Paragraph(
464
  "Anees Qumar Abbasi (Team Lead) | Sharafat Hussain | Salma Asghar | "
465
- "Kaleem Hussain | Munazza Zahra | Kokub Khurishid",
466
  styles["Normal"]
467
  ))
468
 
469
  doc.build(elements)
470
- return file_path
471
 
 
 
 
 
 
472
  # ===============================
473
  # INTERFACE
474
  # ===============================
 
51
  Follow-up Recommendations
52
 
53
  Keep headings clear.
54
+ End with this line: "Remember, this advice is generated based on the provided information and should not replace the judgment of a qualified doctor.
55
+ It is essential to consult a qualified doctor for personalized advice and treatment reminder to consult qualified doctor."
56
  """
57
 
58
  response = client.chat.completions.create(
 
241
  # ===============================
242
  # PDF GENERATION
243
  # ===============================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  def generate_pdf(*inputs):
245
 
246
  global last_basic_data, last_llm_report
 
339
  elements.append(Paragraph(d["recommendation"], styles["Normal"]))
340
  elements.append(Spacer(1,0.4*inch))
341
 
342
+ # ---- DETAILED AI REPORT ----
 
 
343
  if last_llm_report:
344
  elements.append(Paragraph("<b>Detailed AI Report</b>", heading_style))
345
  elements.append(Spacer(1,0.2*inch))
 
352
  if not line:
353
  continue
354
 
 
355
  if "consult a qualified doctor" in line.lower():
356
  continue
357
 
 
358
  if line.startswith("##"):
359
  clean_heading = line.replace("##", "").strip()
360
  elements.append(Spacer(1,0.2*inch))
 
363
  )
364
  else:
365
  elements.append(Paragraph(line, styles["Normal"]))
 
366
 
367
  elements.append(Spacer(1,0.5*inch))
368
 
 
381
  elements.append(Paragraph("<b>Team Chinar AI (AJK)</b>", styles["Normal"]))
382
  elements.append(Paragraph(
383
  "Anees Qumar Abbasi (Team Lead) | Sharafat Hussain | Salma Asghar | "
384
+ "Kaleem Hussain | Munazza Zahra | Kokub Khhurishid",
385
  styles["Normal"]
386
  ))
387
 
388
  doc.build(elements)
 
389
 
390
+ # ✅ SUCCESS POPUP MESSAGE (Added Feature)
391
+
392
+ gr.Info("Report Generated Successfully! Please download it below.")
393
+
394
+ return file_path
395
  # ===============================
396
  # INTERFACE
397
  # ===============================