s297941863 commited on
Commit
3224a6c
·
verified ·
1 Parent(s): 8208f6d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # 加载预训练的情感分析模型
5
+ classifier = pipeline("sentiment-analysis")
6
+
7
+ # 定义分类函数
8
+ def classify_text(text):
9
+ result = classifier(text)
10
+ return result[0]
11
+
12
+ # 创建 Gradio 界面
13
+ iface = gr.Interface(
14
+ fn=classify_text,
15
+ inputs="text",
16
+ outputs="label"
17
+ )
18
+
19
+ # 启动应用
20
+ iface.launch()