Spaces:
Runtime error
Runtime error
Commit
·
24a6217
1
Parent(s):
8171156
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spacy
|
| 2 |
+
import spacy_transformers
|
| 3 |
+
|
| 4 |
+
nlp = spacy.load("en_core_web_trf")
|
| 5 |
+
|
| 6 |
+
examples = [
|
| 7 |
+
"Does Chicago have any stores and does Joe live here?",
|
| 8 |
+
]
|
| 9 |
+
|
| 10 |
+
def ner(text):
|
| 11 |
+
doc = nlp(text)
|
| 12 |
+
final_output = []
|
| 13 |
+
|
| 14 |
+
for ent in doc.ents:
|
| 15 |
+
output = {'entity': ent.label_, 'word': ent.text, 'start': int(ent.start_char), 'end': int(ent.end_char)}
|
| 16 |
+
final_output.append(output)
|
| 17 |
+
|
| 18 |
+
return {"text": text, "entities": final_output}
|
| 19 |
+
|
| 20 |
+
demo = gr.Interface(ner,
|
| 21 |
+
gr.Textbox(placeholder="Enter sentence here..."),
|
| 22 |
+
gr.HighlightedText(),
|
| 23 |
+
examples=examples)
|
| 24 |
+
|
| 25 |
+
if __name__ == '__main__':
|
| 26 |
+
demo.launch(debug=True)
|