ShubhamMhaske commited on
Commit
48f37f5
·
verified ·
1 Parent(s): 4a8e476

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -28,18 +28,25 @@ ner_pipe = pipeline(
28
  def run_ner(text: str):
29
  if not text.strip():
30
  return {"text": "", "entities": []}, []
 
31
  out = ner_pipe(text)
32
- # Gradio HighlightedText format
33
  highlighted = {
34
  "text": text,
35
  "entities": [
36
- {"entity": r["entity_group"], "start": int(r["start"]), "end": int(r["end"]), "score": float(r["score"])}
 
 
 
 
 
37
  for r in out
38
  ],
39
  }
40
- # also return raw rows for inspection
 
41
  rows = [
42
- {"entity": r["entity_group"], "word": r["word"], "score": float(r["score"]), "start": int(r["start"]), "end": int(r["end"])}
43
  for r in out
44
  ]
45
  return highlighted, rows
@@ -48,7 +55,11 @@ with gr.Blocks() as demo:
48
  gr.Markdown("# 🩺 Biomedical NER (offline, local model)")
49
  inp = gr.Textbox(label="Enter text", value="Patient has a history of asthma treated with albuterol.")
50
  ner_view = gr.HighlightedText(label="Entities", combine_adjacent=True)
51
- table = gr.Dataframe(label="Raw predictions", interactive=False)
 
 
 
 
52
  inp.change(run_ner, inp, [ner_view, table])
53
 
54
  demo.launch(debug=True)
 
28
  def run_ner(text: str):
29
  if not text.strip():
30
  return {"text": "", "entities": []}, []
31
+
32
  out = ner_pipe(text)
33
+
34
  highlighted = {
35
  "text": text,
36
  "entities": [
37
+ {
38
+ "entity": r["entity_group"],
39
+ "start": int(r["start"]),
40
+ "end": int(r["end"]),
41
+ "score": float(r["score"]),
42
+ }
43
  for r in out
44
  ],
45
  }
46
+
47
+ # list-of-lists in a fixed column order
48
  rows = [
49
+ [r["entity_group"], r["word"], float(r["score"]), int(r["start"]), int(r["end"])]
50
  for r in out
51
  ]
52
  return highlighted, rows
 
55
  gr.Markdown("# 🩺 Biomedical NER (offline, local model)")
56
  inp = gr.Textbox(label="Enter text", value="Patient has a history of asthma treated with albuterol.")
57
  ner_view = gr.HighlightedText(label="Entities", combine_adjacent=True)
58
+ table = gr.Dataframe(
59
+ label="Raw predictions",
60
+ headers=["entity", "word", "score", "start", "end"], # <-- headers for list-of-lists
61
+ interactive=False,
62
+ )
63
  inp.change(run_ner, inp, [ner_view, table])
64
 
65
  demo.launch(debug=True)