Spaces:
Runtime error
Runtime error
File size: 856 Bytes
24a6217 d04dda9 24a6217 604e51a 24a6217 40fd323 24a6217 f44e244 40fd323 f44e244 24a6217 40fd323 24a6217 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import spacy
import spacy_transformers
import gradio as gr
nlp = spacy.load("en_core_web_sm")
examples = [
"Does Chicago have any stores and does Joe live here?",
]
def ner(text):
doc = nlp(text)
final_output = []
flagged_categories = ["CARDINAL", "DATE", "MONEY", "PERCENT", "QUANTITY", "TIME", "ORDINAL"]
for ent in doc.ents:
label = ent.label_
if label not in flagged_categories:
output = {'entity': ent.label_, "word": ent.text, "start": int(ent.start_char), "end": int(ent.end_char)}
final_output.append(output)
return {"text": text, "entities": final_output}
demo = gr.Interface(ner,
gr.Textbox(placeholder="Enter sentence here..."),
gr.HighlightedText(),
examples=examples)
if __name__ == "__main__":
demo.launch(debug=True) |