import gradio as gr | |
from transformers import pipeline | |
# 使用 Hugging Face 的 fill-mask 模型 | |
classifier = pipeline("fill-mask") | |
def fill_mask(text): | |
# 返回 top 5 的填充结果 | |
results = classifier(text, top_k=5) | |
return [f"{res['sequence']} (score: {res['score']:.4f})" for res in results] | |
# 创建 Gradio 界面 | |
demo = gr.Interface(fn=fill_mask, inputs="text", outputs="text") | |
# 启动应用 | |
demo.launch() | |