Spaces:
Running
Running
Commit
·
bc05f33
1
Parent(s):
023a91a
Cleanup and re-add rating
Browse files
app.py
CHANGED
|
@@ -6,8 +6,12 @@ import gradio as gr
|
|
| 6 |
import pandas as pd
|
| 7 |
from transformers import pipeline, AutoTokenizer, AutoModelForTokenClassification
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
plt.switch_backend("Agg")
|
| 13 |
|
|
@@ -43,23 +47,26 @@ def run_ner(text):
|
|
| 43 |
for x in raw
|
| 44 |
],
|
| 45 |
}
|
| 46 |
-
|
| 47 |
grouped = Counter((x["entity_group"] for x in raw))
|
| 48 |
rows = [[k, v] for k, v in grouped.items()]
|
| 49 |
figure = plot_to_figure(grouped)
|
| 50 |
-
return ner_content, rows, figure
|
| 51 |
|
| 52 |
|
| 53 |
with gr.Blocks() as demo:
|
| 54 |
note = gr.Textbox(label="Note text")
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
demo.launch()
|
|
|
|
| 6 |
import pandas as pd
|
| 7 |
from transformers import pipeline, AutoTokenizer, AutoModelForTokenClassification
|
| 8 |
|
| 9 |
+
MODELS = ["d4data/biomedical-ner-all", "samrawal/bert-base-uncased_clinical-ner"]
|
| 10 |
+
|
| 11 |
+
current_model = MODELS[1]
|
| 12 |
+
|
| 13 |
+
tokenizer = AutoTokenizer.from_pretrained(current_model)
|
| 14 |
+
model = AutoModelForTokenClassification.from_pretrained(current_model)
|
| 15 |
|
| 16 |
plt.switch_backend("Agg")
|
| 17 |
|
|
|
|
| 47 |
for x in raw
|
| 48 |
],
|
| 49 |
}
|
| 50 |
+
label = examples.get(text, None)
|
| 51 |
grouped = Counter((x["entity_group"] for x in raw))
|
| 52 |
rows = [[k, v] for k, v in grouped.items()]
|
| 53 |
figure = plot_to_figure(grouped)
|
| 54 |
+
return label, ner_content, rows, figure
|
| 55 |
|
| 56 |
|
| 57 |
with gr.Blocks() as demo:
|
| 58 |
note = gr.Textbox(label="Note text")
|
| 59 |
+
submit = gr.Button("Submit")
|
| 60 |
+
# with gr.Accordion("Examples", open=False):
|
| 61 |
+
example_dropdown = gr.Dropdown(label="Examples", choices=list(examples.keys()))
|
| 62 |
+
example_dropdown.change(
|
| 63 |
+
lambda x: gr.Textbox.update(value=x), inputs=example_dropdown, outputs=note
|
| 64 |
+
)
|
| 65 |
+
rating = gr.Label(label="Given rating")
|
| 66 |
+
highlight = gr.HighlightedText(label="NER", combine_adjacent=True)
|
| 67 |
+
table = gr.Dataframe(headers=["Entity", "Count"])
|
| 68 |
+
plot = gr.Plot(label="Bar")
|
| 69 |
+
submit.click(run_ner, [note], [rating, highlight, table, plot])
|
| 70 |
+
note.submit(run_ner, [note], [rating, highlight, table, plot])
|
| 71 |
|
| 72 |
demo.launch()
|