app_ner / app.py
hcy5561's picture
Upload app.py
62b43fd verified
# -*- coding: utf-8 -*-
"""Gradio-App-for-NER.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/18duqjwAF3DkX1CsVvr0mc0T763VCd5Q4
<a href="https://colab.research.google.com/github/TirendazAcademy/Hugging-Face-Tutorials/blob/main/Gradio_App_for_Ner.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
# Gradio Demo: ner_pipeline
"""
from transformers import pipeline
import gradio as gr
ner_pipeline = pipeline("ner", model = "Tirendaz/roberta-base-NER")
examples = [
"My name is Tim and I live in California.",
"Ich arbeite bei Google in Berlin",
"Ali, Ankara'lı mı?"
]
def ner(text):
output = ner_pipeline(text, aggregation_strategy="simple")
return {"text": text, "entities": output}
demo = gr.Interface(ner,
gr.Textbox(placeholder="Enter sentence here..."),
gr.HighlightedText(),
examples=examples)
demo.launch(inline=False, share=True)