Mhammad Ibrahim
Fix pipeline type to token-classification for NER model
7aa02fc
raw
history blame
735 Bytes
# import gradio as gr
# def greet(name):
# return "Hello " + name + "!!"
# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
# demo.launch()
import gradio as gr
from transformers import pipeline
# Load model from Hugging Face Hub
classifier = pipeline("token-classification", model="Mhammad2023/bert-finetuned-ner", from_tf=True)
def predict(text):
results = classifier(text)
if not results:
return "No entities found"
output = []
for entity in results:
output.append(f"{entity['word']}: {entity['entity']} ({round(entity['score']*100, 2)}%)")
return "\n".join(output)
gr.Interface(fn=predict, inputs="text", outputs="text", title="Named Entity Recognition").launch()