| import gradio as gr | |
| from transformers import pipeline | |
| unmasker = pipeline('fill-mask', model='bert-base-uncased') | |
| def fill_mask(text): | |
| unmasked = unmasker(text) | |
| output = {} | |
| for unmask in unmasked: | |
| output[unmask["token_str"]] = unmask["score"] | |
| return output | |
| examples = [["Hello I'm a [MASK] model."], ["[MASK] is my favourite sports."]] | |
| demo = gr.Interface(fn=fill_mask, inputs=gr.Textbox(lines=1, label="Input"), outputs=gr.Label(label="Output"), examples=examples) | |
| demo.launch() |