add examples
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ os.system("pip3 install torch==1.10.1+cpu torchvision==0.11.2+cpu torchaudio==0.
|
|
5 |
"https://download.pytorch.org/whl/cpu/torch_stable.html")
|
6 |
|
7 |
import gradio as gr
|
8 |
-
from transformers import
|
9 |
|
10 |
import spacy
|
11 |
from spacy import displacy
|
@@ -25,14 +25,12 @@ options = {"ents": ["OSOBA",
|
|
25 |
"ORGANIZÁCIA": "lightcoral",
|
26 |
"LOKALITA": "lightgreen"}}
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
ner_pipeline = pipeline(task='ner', model=model, tokenizer=tokenizer)
|
31 |
-
nlp = spacy.blank("en")
|
32 |
|
33 |
|
34 |
-
def apply_ner(
|
35 |
-
classifications = ner_pipeline(
|
36 |
|
37 |
entities = []
|
38 |
for i in range(len(classifications)):
|
@@ -43,7 +41,7 @@ def apply_ner(text: str):
|
|
43 |
j += 1
|
44 |
entities.append((ner_map[classifications[i]['entity']].split('-')[1], classifications[i]['start'],
|
45 |
classifications[j - 1]['end']))
|
46 |
-
doc = nlp(
|
47 |
|
48 |
ents = []
|
49 |
for ee in entities:
|
@@ -55,5 +53,12 @@ def apply_ner(text: str):
|
|
55 |
|
56 |
|
57 |
intf = gr.Interface(fn=apply_ner, inputs="text", outputs="html", title='Slovak Named Entity Recognition',
|
58 |
-
allow_flagging=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
intf.launch()
|
|
|
5 |
"https://download.pytorch.org/whl/cpu/torch_stable.html")
|
6 |
|
7 |
import gradio as gr
|
8 |
+
from transformers import pipeline
|
9 |
|
10 |
import spacy
|
11 |
from spacy import displacy
|
|
|
25 |
"ORGANIZÁCIA": "lightcoral",
|
26 |
"LOKALITA": "lightgreen"}}
|
27 |
|
28 |
+
ner_pipeline = pipeline(task='ner', model="crabz/slovakbert-ner")
|
29 |
+
nlp = spacy.blank("sk")
|
|
|
|
|
30 |
|
31 |
|
32 |
+
def apply_ner(sentence: str):
|
33 |
+
classifications = ner_pipeline(sentence)
|
34 |
|
35 |
entities = []
|
36 |
for i in range(len(classifications)):
|
|
|
41 |
j += 1
|
42 |
entities.append((ner_map[classifications[i]['entity']].split('-')[1], classifications[i]['start'],
|
43 |
classifications[j - 1]['end']))
|
44 |
+
doc = nlp(sentence)
|
45 |
|
46 |
ents = []
|
47 |
for ee in entities:
|
|
|
53 |
|
54 |
|
55 |
intf = gr.Interface(fn=apply_ner, inputs="text", outputs="html", title='Slovak Named Entity Recognition',
|
56 |
+
allow_flagging=False,
|
57 |
+
examples=[["Laboratóriá Úradu verejného zdravotníctva sekvenovaním potvrdili výskyt ďalších "
|
58 |
+
"štyroch prípadov variantu omikron na Slovensku."],
|
59 |
+
["Čaputová opakovane tvrdí, že \"spravodlivosť na Slovensku neplatí vždy pre všetkých "
|
60 |
+
"rovnako\"."]],
|
61 |
+
description="Named Entity Recognition (NER) labels persons, organizations and locations in the "
|
62 |
+
"given sentence.",
|
63 |
+
article="")
|
64 |
intf.launch()
|