paulm0016 commited on
Commit
0cd4315
·
verified ·
1 Parent(s): fa4c475

Create newtest

Browse files
Files changed (1) hide show
  1. newtest +16 -0
newtest ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # 使用 Hugging Face 的 fill-mask 模型
5
+ classifier = pipeline("fill-mask")
6
+
7
+ def fill_mask(text):
8
+ # 返回 top 5 的填充结果
9
+ results = classifier(text, top_k=5)
10
+ return [f"{res['sequence']} (score: {res['score']:.4f})" for res in results]
11
+
12
+ # 创建 Gradio 界面
13
+ demo = gr.Interface(fn=fill_mask, inputs="text", outputs="text")
14
+
15
+ # 启动应用
16
+ demo.launch()