Spaces:
Runtime error
Runtime error
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() |