import gradio as gr from transformers import pipeline fill_mask = pipeline("fill-mask", model="SamJoshua/EsperBERTo") def predict(text: str): if text.count("") != 1: raise gr.Error("Please include exactly one token in the text.") return {r["token_str"].strip(): r["score"] for r in fill_mask(text, top_k=5)} demo = gr.Interface( fn=predict, inputs=gr.Textbox(label="Esperanto text with one ", value="La suno ."), outputs=gr.Label(num_top_classes=5, label="Predictions"), examples=[["La suno ."], ["Jen la komenco de bela ."]], title="EsperBERTo fill-mask", cache_examples=False, ) if __name__ == "__main__": demo.launch()