Spaces:
Running
Running
try loading ner_dict from label_dicts
Browse files- interfaces/ner.py +3 -1
interfaces/ner.py
CHANGED
@@ -9,6 +9,8 @@ from transformers import AutoModelForSequenceClassification
|
|
9 |
from transformers import AutoTokenizer
|
10 |
from huggingface_hub import HfApi
|
11 |
|
|
|
|
|
12 |
languages = [
|
13 |
"English", "Hungarian", "Multilingual"
|
14 |
]
|
@@ -35,7 +37,7 @@ def named_entity_recognition(text, language):
|
|
35 |
doc = pipeline(text)
|
36 |
entities = [{"entity":ent.label_, "start":ent.start_char, "end":ent.end_char} for ent in doc.ents]
|
37 |
labels_used = [ent.label_ for ent in doc.ents]
|
38 |
-
legend = "<ul>"+"".join([f"<li> <b>{label}</b> = <i>{
|
39 |
output = {"text":text, "entities":entities}
|
40 |
model_id_hf = f"huspacy/{model_id}" if model_id.startswith("hu") else f"spacy/{model_id}"
|
41 |
output_info = legend + f'<p style="text-align: center; display: block">Prediction was made using the <a href="https://huggingface.co/{model_id_hf}">{model_id_hf}</a> model.</p> <ul> {" ".join(legend)} </ul>'
|
|
|
9 |
from transformers import AutoTokenizer
|
10 |
from huggingface_hub import HfApi
|
11 |
|
12 |
+
from label_dicts import NER_DICT
|
13 |
+
|
14 |
languages = [
|
15 |
"English", "Hungarian", "Multilingual"
|
16 |
]
|
|
|
37 |
doc = pipeline(text)
|
38 |
entities = [{"entity":ent.label_, "start":ent.start_char, "end":ent.end_char} for ent in doc.ents]
|
39 |
labels_used = [ent.label_ for ent in doc.ents]
|
40 |
+
legend = "<p>Legend:</p><ul>"+"".join([f"<li> <b>{label}</b> = <i>{NER_DICT[label]}</i> </li>" for label in set(labels_used)])+"</ul>"
|
41 |
output = {"text":text, "entities":entities}
|
42 |
model_id_hf = f"huspacy/{model_id}" if model_id.startswith("hu") else f"spacy/{model_id}"
|
43 |
output_info = legend + f'<p style="text-align: center; display: block">Prediction was made using the <a href="https://huggingface.co/{model_id_hf}">{model_id_hf}</a> model.</p> <ul> {" ".join(legend)} </ul>'
|