Spaces:
Sleeping
Sleeping
Commit
·
621a7b7
1
Parent(s):
bc05f33
Remove rating
Browse files
app.py
CHANGED
|
@@ -15,10 +15,10 @@ model = AutoModelForTokenClassification.from_pretrained(current_model)
|
|
| 15 |
|
| 16 |
plt.switch_backend("Agg")
|
| 17 |
|
| 18 |
-
examples =
|
| 19 |
with open("examples.json", "r") as f:
|
| 20 |
content = json.load(f)
|
| 21 |
-
examples = {x[
|
| 22 |
|
| 23 |
pipe = pipeline("ner", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
|
| 24 |
|
|
@@ -47,26 +47,24 @@ def run_ner(text):
|
|
| 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
|
| 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=
|
| 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], [
|
| 70 |
-
note.submit(run_ner, [note], [
|
| 71 |
|
| 72 |
demo.launch()
|
|
|
|
| 15 |
|
| 16 |
plt.switch_backend("Agg")
|
| 17 |
|
| 18 |
+
examples = []
|
| 19 |
with open("examples.json", "r") as f:
|
| 20 |
content = json.load(f)
|
| 21 |
+
examples = [f"{x['label']}: {x['text']}" for x in content]
|
| 22 |
|
| 23 |
pipe = pipeline("ner", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
|
| 24 |
|
|
|
|
| 47 |
for x in raw
|
| 48 |
],
|
| 49 |
}
|
|
|
|
| 50 |
grouped = Counter((x["entity_group"] for x in raw))
|
| 51 |
rows = [[k, v] for k, v in grouped.items()]
|
| 52 |
figure = plot_to_figure(grouped)
|
| 53 |
+
return ner_content, rows, figure
|
| 54 |
|
| 55 |
|
| 56 |
with gr.Blocks() as demo:
|
| 57 |
note = gr.Textbox(label="Note text")
|
| 58 |
submit = gr.Button("Submit")
|
| 59 |
# with gr.Accordion("Examples", open=False):
|
| 60 |
+
example_dropdown = gr.Dropdown(label="Examples", choices=examples)
|
| 61 |
example_dropdown.change(
|
| 62 |
lambda x: gr.Textbox.update(value=x), inputs=example_dropdown, outputs=note
|
| 63 |
)
|
|
|
|
| 64 |
highlight = gr.HighlightedText(label="NER", combine_adjacent=True)
|
| 65 |
table = gr.Dataframe(headers=["Entity", "Count"])
|
| 66 |
plot = gr.Plot(label="Bar")
|
| 67 |
+
submit.click(run_ner, [note], [highlight, table, plot])
|
| 68 |
+
note.submit(run_ner, [note], [highlight, table, plot])
|
| 69 |
|
| 70 |
demo.launch()
|