File size: 1,433 Bytes
77f7257
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adb08e0
 
 
77f7257
adb08e0
 
 
 
77f7257
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline
import gradio as gr
import base64

model_checkpoint2 = "dccuchile/bert-base-spanish-wwm-cased"

mask_filler = pipeline(
    "fill-mask", model=model_checkpoint2,tokenizer=model_checkpoint2
)

def fill_mask_interface(sentence):
    results = mask_filler(sentence)
    #suggestions = [f"{result['token_str']} (confidence: {result['score']:.4f})" for result in results]
    dictt ={}
    for text,score in zip([d['token_str'] for d in results],[d['score'] for d in results]):
      dictt[text] = score
    return dictt


with open("Iso_Logotipo_Ceibal.png", "rb") as image_file:
    encoded_image = base64.b64encode(image_file.read()).decode()

description = """
<p>
<center>
<img src='data:image/jpg;base64,{}' width=200px>
Interact煤a con este espacio para probar la predicci贸n de palabras en una frase con una palabra enmascarada. La palabra enmascarada debe ser [MASK] y s贸lo  una por frase.
</center>
</p>
""".format(encoded_image)


textbox = gr.Textbox(label="Agrega tu frase con una palabra enmascarada aqu铆!", placeholder="Hola, [MASK] est谩s?", lines=2)

gr.Interface(fn=fill_mask_interface, 
             inputs=textbox, 
             outputs="label",
             title = "Uso de AI para la predicci贸n de palabras enmascaradas.",
             description = description,
             examples=[["Hola, c贸mo te lleva el [MASK]?"], ["D贸nde deber铆amos [MASK]?"]]
             ).launch()