File size: 1,046 Bytes
62b43fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- 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)