Update function
Browse files
app.py
CHANGED
|
@@ -2,10 +2,27 @@ import spacy
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def get_named_entity(text):
|
| 6 |
nlp = spacy.load("en_core_web_sm")
|
| 7 |
doc = nlp(text)
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
iface = gr.Interface(fn=get_named_entity, inputs="text", outputs="text")
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
|
| 5 |
+
def make_ent_dict(list):
|
| 6 |
+
ent_dict = {
|
| 7 |
+
'ORG': '',
|
| 8 |
+
'PERSON': '',
|
| 9 |
+
'GPE': '',
|
| 10 |
+
'DATE': '',
|
| 11 |
+
'TIME': '',
|
| 12 |
+
'MONEY': '',
|
| 13 |
+
'PERCENT': '',
|
| 14 |
+
}
|
| 15 |
+
for item in list:
|
| 16 |
+
if item[0] in ent_dict.keys():
|
| 17 |
+
ent_dict[item[0]] = item[1]
|
| 18 |
+
return ent_dict
|
| 19 |
+
|
| 20 |
+
|
| 21 |
def get_named_entity(text):
|
| 22 |
nlp = spacy.load("en_core_web_sm")
|
| 23 |
doc = nlp(text)
|
| 24 |
+
ent_list = [(ent.label_, ent.text) for ent in doc.ents]
|
| 25 |
+
return make_ent_dict(ent_list)
|
| 26 |
|
| 27 |
|
| 28 |
iface = gr.Interface(fn=get_named_entity, inputs="text", outputs="text")
|