andrewgleave commited on
Commit
621a7b7
1 Parent(s): bc05f33

Remove rating

Browse files
Files changed (1) hide show
  1. app.py +6 -8
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["text"]: x["label"] for x in content}
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 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()
 
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()