Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# load ner model
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
ner_pipe = pipeline(
|
| 5 |
+
'ner',
|
| 6 |
+
model= 'dslim/bert-base-NER',
|
| 7 |
+
aggregation_strategy = 'simple'
|
| 8 |
+
)
|
| 9 |
+
def ext_entities(sentence):
|
| 10 |
+
doc = ner_pipe(sentence.title())
|
| 11 |
+
outputs = ''
|
| 12 |
+
for t in doc:
|
| 13 |
+
outputs += f"{t['word']} - {t['entity_group']}\n{t['score']}\n"
|
| 14 |
+
return outputs
|
| 15 |
+
import gradio as gr
|
| 16 |
+
|
| 17 |
+
demo = gr.Interface(fn=ext_entities,inputs='text',outputs='text',title='Extract Entities')
|
| 18 |
+
demo.launch()
|