File size: 893 Bytes
f598a7e
 
1b79b01
34e4e6e
4500091
34e4e6e
1b79b01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline
model_name = 'mrm8488/bert-spanish-cased-finetuned-ner'
# model_name = 'MMG/xlm-roberta-large-ner-spanish'
# pipe = pipeline("image-classification")
pipe = pipeline("ner", model=model_name, aggregation_strategy="simple")

def infer_ner(text):
    output = pipe(text)
    for d in output:
        print(d)
        d['entity'] = d['entity_group']

    return{
        'text': text,
        'entities': output
    },  output

gr.Interface(
    fn=infer_ner,
    inputs=gr.Textbox(),
    outputs=[gr.HighlightedText(), gr.Textbox()],
    examples=[
        "Mauricio Macri, Cristina Fernández y Alberto Fernández se juntaron en la Casa Rosada",
        "Lionel Messi marcó un gol contra Arabia Saudita",
        "Vamos Boca Juniors Campeón del mundo",
        "Lo importante no es que vengas sino que vuelvas, Unicenter!",
    ]
).launch()