NER-Demo / app.py
ShakhzoDavronov's picture
Update app.py
88f8544 verified
# -*- coding: utf-8 -*-
"""ner_app.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1EOyiqIkIiPPP4oj114POiTpju4Ri8Xxn
"""
#!pip install gradio
#!pip install transformers
import gradio as gr
from transformers import pipeline
ner_model=pipeline('ner',model="ShakhzoDavronov/electra-ner-token-classification")
ner_model('Amazon announced its plans to open a new headquarters in Virginia, aiming to create over 25,000 jobs in the area by 2030.',aggregation_strategy='average')
def ner(text):
output=ner_model(text,aggregation_strategy='average')
return {'text':text,'entities':output}
input_textbox=gr.Textbox(label='Type text here to get named entities',placeholder='type...',lines=4)
output_textbox=gr.HighlightedText(label='Named entities')
samples=["Elon founded SpaceX.","The conference will be held in San Francisco next April.","Amazon announced its plans to open a new headquarters in Virginia, aiming to create over 25,000 jobs in the area by 2030."]
demo=gr.Interface(fn=ner, inputs=input_textbox, outputs=output_textbox,examples=samples)
demo.launch(share=True)