File size: 1,158 Bytes
6514fd7 18fbe0f 6514fd7 9219f65 7ddc08e 9219f65 e2835eb 23d7bd4 27dad55 6514fd7 18fbe0f 6514fd7 ef0b957 0639b8b 45bb59d 0639b8b 6514fd7 |
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 33 34 35 36 |
from transformers import pipeline
import gradio as gr
model_checkpoint = "MuntasirHossain/bert-finetuned-ner"
model = pipeline("ner", model=model_checkpoint, aggregation_strategy="simple")
# def ner(text):
# output = model(text)
# return {"text": text, "entities": output}
def ner(text):
a = ""
results = model(text)
for result in results:
a += result['word'] + " : " + result['entity_group'] + ", "
a = a[0:len(a)-3] # removes the ', ' at the end of text
return a
description = "This AI model is trained to identify and classify named entities in unstructured text."
title = "Named Entity Recognition"
theme = "grass"
examples=["Mount Everest is Earth's highest mountain, located in the Mahalangur Himal sub-range of the Himalayas. Edmund Hillary and Tenzing Norgay were the first climbers confirmed\
to have reached the summit of Mount Everest on May 29, 1953."]
gr.Interface(fn=ner,
inputs="textbox",
outputs="text",
# gr.Textbox(placeholder="Enter sentence here..."),
# gr.HighlightedText(),
title=title,
theme = theme,
description=description,
examples=examples,
).launch() |