kansei / app.py
deniandriancode's picture
Update app.py
0ce0c70
raw
history blame
No virus
481 Bytes
import gradio as gr
from transformers import pipeline
import random
top_k = 10
masker = pipeline("fill-mask", model="distilroberta-base")
def get_mask(txt):
txt = txt.replace("...", masker.tokenizer.mask_token, count=1)
result = masker(txt, top_k=top_k)
random.shuffle(result)
result_seq = []
for r in result:
result_seq.append(r['sequence'])
return result_seq
inf = gr.Interface(fn=get_mask, inputs="text", outputs=["text"] * top_k)
inf.launch()