File size: 954 Bytes
165560d
 
 
 
 
 
 
 
 
489d4bc
165560d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489d4bc
 
 
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
37
38
39
40
41
42
43
# import gradio as gr

# def greet(name):
#     return "Hello Mr." + name + "!!"

# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
# iface.launch()


import gradio as gr
from numpy import kaiser

from transformers import pipeline

fill_mask = pipeline("fill-mask", model="./QuijoBERT", tokenizer = './QuijoBERT')

def predict(text):
    
    res_dict = {}
    x = fill_mask(text)
    print('x')
    for i in range(len(x)):
        k = x[i]['sequence']
        e = x[i]['score']
        print(k, e) 
        if e >= 0.05:
            res_dict[k] = e
    print (res_dict)
    return res_dict
    #return {x[0]["sequence"], x[0]["score"]}

# texto = 'en un lugar de la <mask>'
# print(predict(texto))

iface = gr.Interface(
    fn=predict, 
    inputs='text',
    outputs ='label',
    examples=['En un lugar de la <mask>', 'En verdad, <mask> Sancho', 'Cómo has estado, bien mío, <mask> de mis ojos, compañero mío']
)


iface.launch()