miculpionier/Fill-Mask
1
1import gradio2from transformers import pipeline3 4unmasker = pipeline('fill-mask', model='bert-large-uncased-whole-word-masking')5 6 7def predict_words(text):8 results = unmasker(text)9 word_list = [f"{result['token_str']}: {result['score']:.2%}" for result in results]10 return word_list[:5]11 12 13inputs = [14 gradio.components.Textbox(label="Enter Text (Use [MASK] for the masked word; Use it only once)",15 placeholder="Enter your text here."),16]17 18outputs = [19 gradio.components.Textbox(label="Prediction 1"),20 gradio.components.Textbox(label="Prediction 2"),21 gradio.components.Textbox(label="Prediction 3"),22 gradio.components.Textbox(label="Prediction 4"),23 gradio.components.Textbox(label="Prediction 5")24]25 26title = "Fill Mask (bert-large-uncased-whole-word-masking)"27 28gradio.Interface(fn=predict_words, inputs=inputs, outputs=outputs, title=title, allow_flagging="never",29 css="footer{display:none !important}").launch()30 