sujataprakashdatycs commited on
Commit
81f8d2d
·
verified ·
1 Parent(s): d4db447

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -109,7 +109,6 @@ def json_to_markdown(data) -> str:
109
  md += f"<p><b>MEAT Rationale:</b> {diag.get('meat_rationale','')}</p>"
110
  md += "</details>"
111
 
112
- # --- MODIFICATION: Filter to only show present comorbidities ---
113
  if "comorbidities" in diag and diag["comorbidities"]:
114
  present_comorbidities = [c for c in diag["comorbidities"] if c.get("is_present")]
115
  if present_comorbidities:
@@ -117,7 +116,6 @@ def json_to_markdown(data) -> str:
117
  for c in present_comorbidities:
118
  md += f"<li>✅ <b>{c.get('condition')}</b><br/><i>{c.get('rationale')}</i></li>"
119
  md += "</ul></details>"
120
- # --- END OF MODIFICATION ---
121
 
122
  md += "</div>"
123
  return md
@@ -286,6 +284,12 @@ def pdf_to_iframe(file):
286
  except Exception as e:
287
  return f"<p style='color:red;'>Failed to display PDF: {e}</p>"
288
 
 
 
 
 
 
 
289
 
290
  # ---------- Gradio UI ----------
291
  with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
@@ -311,7 +315,10 @@ with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
311
  value="<div style='border:2px solid #1e40af; border-radius:12px; padding:15px; background-color:#f0f9ff;'>📄 Upload a PDF and click <b>Run Validation</b> to start.</div>",
312
  )
313
 
 
314
  pdf_upload.change(fn=pdf_to_iframe, inputs=pdf_upload, outputs=pdf_preview)
 
 
315
 
316
  run_btn.click(
317
  fn=process_pipeline,
@@ -335,8 +342,6 @@ if __name__ == "__main__":
335
  )
336
 
337
 
338
-
339
-
340
 
341
  # import os
342
  # import gradio as gr
 
109
  md += f"<p><b>MEAT Rationale:</b> {diag.get('meat_rationale','')}</p>"
110
  md += "</details>"
111
 
 
112
  if "comorbidities" in diag and diag["comorbidities"]:
113
  present_comorbidities = [c for c in diag["comorbidities"] if c.get("is_present")]
114
  if present_comorbidities:
 
116
  for c in present_comorbidities:
117
  md += f"<li>✅ <b>{c.get('condition')}</b><br/><i>{c.get('rationale')}</i></li>"
118
  md += "</ul></details>"
 
119
 
120
  md += "</div>"
121
  return md
 
284
  except Exception as e:
285
  return f"<p style='color:red;'>Failed to display PDF: {e}</p>"
286
 
287
+ # --- NEW FUNCTION: To reset the UI when the PDF is cleared ---
288
+ def clear_outputs():
289
+ initial_md = "<div style='border:2px solid #1e40af; border-radius:12px; padding:15px; background-color:#f0f9ff;'>📄 Upload a PDF and click <b>Run Validation</b> to start.</div>"
290
+ initial_preview = "<p>Upload a PDF to preview</p>"
291
+ return initial_md, initial_preview
292
+ # --- END OF NEW FUNCTION ---
293
 
294
  # ---------- Gradio UI ----------
295
  with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
 
315
  value="<div style='border:2px solid #1e40af; border-radius:12px; padding:15px; background-color:#f0f9ff;'>📄 Upload a PDF and click <b>Run Validation</b> to start.</div>",
316
  )
317
 
318
+ # --- MODIFICATION: Added .clear() event handler ---
319
  pdf_upload.change(fn=pdf_to_iframe, inputs=pdf_upload, outputs=pdf_preview)
320
+ pdf_upload.clear(fn=clear_outputs, inputs=[], outputs=[output_md, pdf_preview])
321
+ # --- END OF MODIFICATION ---
322
 
323
  run_btn.click(
324
  fn=process_pipeline,
 
342
  )
343
 
344
 
 
 
345
 
346
  # import os
347
  # import gradio as gr