rayshunp commited on
Commit
43f874c
·
verified ·
1 Parent(s): e61ad79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -227,16 +227,11 @@ def predict(text: str):
227
  # ── 4. Inline word-highlight HTML ──
228
  word_html = _build_highlight_html(tokens, vals_severe)
229
 
230
- # ── 5. SHAP bar/force plot image ──
231
- fig = _build_shap_plot(tokens, vals_severe, text)
232
-
233
- # ── 6. NER Pipeline ──
234
  ner_results = ner_pipe(text)
235
  ner_html = _build_ner_html(text, ner_results)
236
 
237
- return verdict_html, word_html, fig, ner_html # add ner_html
238
-
239
- return verdict_html, word_html, fig
240
 
241
  # ── HTML word highlights ──────────────────────────────────────────────────────
242
  def _build_highlight_html(tokens, values):
@@ -354,11 +349,11 @@ def _build_shap_plot(tokens, values, text):
354
 
355
  # ── Gradio UI ─────────────────────────────────────────────────────────────────
356
  EXAMPLES = [
357
- ["I felt groggy and dizzy after taking Tylenol."],
358
- ["I had a mild headache after the medication."],
359
- ["I experienced severe chest pain and difficulty breathing after the injection."],
360
- ["My stomach felt slightly upset after the pill."],
361
- ["I had an anaphylactic reaction with hives and throat swelling after penicillin."],
362
  ]
363
 
364
  CSS = """
@@ -393,28 +388,27 @@ with gr.Blocks(css=CSS, theme=gr.themes.Base()) as demo:
393
  with gr.Column(scale=1):
394
  text_input = gr.Textbox(
395
  label="Describe your reaction",
396
- placeholder="e.g. I felt groggy and dizzy after taking Tylenol.",
397
- lines=3,
398
  )
399
  analyze_btn = gr.Button("🔍 Analyze Reaction", variant="primary")
400
  gr.Examples(examples=EXAMPLES, inputs=text_input, label="Try an example")
401
-
402
  with gr.Column(scale=1):
403
  verdict_out = gr.HTML(label="Severity Verdict")
404
 
405
  gr.Markdown("### 🎨 Word-Level SHAP Highlights")
406
  highlight_out = gr.HTML(label="Token Highlights")
407
 
408
- gr.Markdown("### 📊 SHAP Token Importance Plot")
409
- plot_out = gr.Plot(label="SHAP Bar Chart")
410
-
411
  gr.Markdown("### 🏥 Medical Entity Recognition")
412
  ner_out = gr.HTML(label="Detected Entities")
413
 
414
  analyze_btn.click(
415
  fn=predict,
416
  inputs=text_input,
417
- outputs=[verdict_out, highlight_out, plot_out, ner_out], # add ner_out
418
  )
 
 
 
419
  if __name__ == "__main__":
420
  demo.launch()
 
227
  # ── 4. Inline word-highlight HTML ──
228
  word_html = _build_highlight_html(tokens, vals_severe)
229
 
230
+ # ── 5. NER Pipeline ──
 
 
 
231
  ner_results = ner_pipe(text)
232
  ner_html = _build_ner_html(text, ner_results)
233
 
234
+ return verdict_html, word_html, ner_html
 
 
235
 
236
  # ── HTML word highlights ──────────────────────────────────────────────────────
237
  def _build_highlight_html(tokens, values):
 
349
 
350
  # ── Gradio UI ─────────────────────────────────────────────────────────────────
351
  EXAMPLES = [
352
+ ["I took ibuprofen for my back pain this morning. About an hour later, I noticed mild stomach discomfort and felt slightly nauseous. The symptoms went away after I ate something."],
353
+ ["I was prescribed amoxicillin for a sinus infection last week. I developed a mild rash on my arms after the second dose. My doctor said it was a minor allergic reaction and switched me to a different antibiotic."],
354
+ ["After receiving the contrast dye injection for my CT scan, I immediately felt my throat tightening and had difficulty breathing. I broke out in hives across my chest and face. The medical team administered epinephrine and I was kept under observation for several hours."],
355
+ ["I am a 67 year old male who started taking metformin for type 2 diabetes last month. I have been experiencing persistent nausea and occasional vomiting since starting the medication. My blood sugar levels have improved but the gastrointestinal side effects are making it difficult to continue."],
356
+ ["My 8 year old daughter was given penicillin for strep throat. Within 30 minutes she complained of dizziness and her lips began to swell. We rushed her to the emergency room where she was treated for anaphylaxis."],
357
  ]
358
 
359
  CSS = """
 
388
  with gr.Column(scale=1):
389
  text_input = gr.Textbox(
390
  label="Describe your reaction",
391
+ placeholder="e.g. I took ibuprofen for my back pain this morning.",
392
+ lines=5,
393
  )
394
  analyze_btn = gr.Button("🔍 Analyze Reaction", variant="primary")
395
  gr.Examples(examples=EXAMPLES, inputs=text_input, label="Try an example")
 
396
  with gr.Column(scale=1):
397
  verdict_out = gr.HTML(label="Severity Verdict")
398
 
399
  gr.Markdown("### 🎨 Word-Level SHAP Highlights")
400
  highlight_out = gr.HTML(label="Token Highlights")
401
 
 
 
 
402
  gr.Markdown("### 🏥 Medical Entity Recognition")
403
  ner_out = gr.HTML(label="Detected Entities")
404
 
405
  analyze_btn.click(
406
  fn=predict,
407
  inputs=text_input,
408
+ outputs=[verdict_out, highlight_out, ner_out],
409
  )
410
+
411
+ if __name__ == "__main__":
412
+ demo.launch()
413
  if __name__ == "__main__":
414
  demo.launch()