brijw/transformers_ner
0
1import gradio as gr2from transformers import AutoTokenizer, AutoModelForTokenClassification,pipeline 3 4tokenizer = AutoTokenizer.from_pretrained("dbmdz/electra-large-discriminator-finetuned-conll03-english")5 6model = AutoModelForTokenClassification.from_pretrained("dbmdz/electra-large-discriminator-finetuned-conll03-english")7 8 9 10ner_pipeline = pipeline("ner",model=model, 11 tokenizer=tokenizer)12 13examples = [14 "where did Wandobire's laptop come from, was it africa or uganda?",15]16 17examples_2 = [18 "The Intern was oriented on ICT setup and Infrastructure of Soroti University, drafted workplan and started off the Internship. Simon was encouraged to take the Internship seriously as there was a lot to learn.",19]20 21examples_3 = [22 "Partially done, expected a better result based on Steven's experienced. More effort needed ...",23]24 25 26 27 28def ner_electra(text):29 output = ner_pipeline(text)30 return {"text": text, "entities": output}31 32 33gr.Interface(ner_electra,34 gr.Textbox(placeholder="Enter sentence here..."), 35 gr.HighlightedText(),36 examples=[[examples],[examples_2],[examples_3],],37 title="Comparative Natural Entity Recognition Model by Brian Joram Wandobire",38 description="takes in a comment as an input and outputs the Entities",39 ).launch()