Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,26 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
5 |
-
|
|
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
# 将两个接口添加到接口组中
|
16 |
-
iface_group = gr.InterfaceGroup([iface_greet, iface_count], title="My Interfaces")
|
17 |
-
|
18 |
-
# 为第一个接口添加一个按钮,点击该按钮将切换到第二个接口
|
19 |
-
iface_greet.add_button("Count Numbers", interface=iface_count)
|
20 |
-
|
21 |
-
# 启动接口组
|
22 |
-
iface_group.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline, AutoTokenizer
|
3 |
|
4 |
+
# 加载模型和分词器
|
5 |
+
model_name = "bert-base-uncased"
|
6 |
+
model = pipeline("text-classification", model=model_name, tokenizer=model_name)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
|
9 |
+
# 定义 Gradio 接口
|
10 |
+
def classify_text(text):
|
11 |
+
# 对输入文本进行分词
|
12 |
+
inputs = tokenizer(text, return_tensors="pt")
|
13 |
+
# 使用模型进行预测
|
14 |
+
outputs = model(inputs)
|
15 |
+
# 获取预测结果
|
16 |
+
label = outputs[0]["label"]
|
17 |
+
score = outputs[0]["score"]
|
18 |
+
return f"Label: {label}, Score: {score:.2f}"
|
19 |
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=classify_text,
|
22 |
+
inputs=gr.inputs.Textbox(),
|
23 |
+
outputs=gr.outputs.HTML(),
|
24 |
+
)
|
25 |
|
26 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|