Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,17 @@
|
|
| 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 |
-
# 创建
|
| 13 |
-
iface = gr.Interface(
|
| 14 |
-
fn=classify_text,
|
| 15 |
-
inputs="text",
|
| 16 |
-
outputs="label"
|
| 17 |
-
)
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
iface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# 加载情感分析模型
|
| 5 |
classifier = pipeline("sentiment-analysis")
|
| 6 |
|
| 7 |
+
# 定义处理用户输入的函数
|
| 8 |
def classify_text(text):
|
| 9 |
+
# 使用模型进行情感分类
|
| 10 |
result = classifier(text)
|
| 11 |
return result[0]
|
| 12 |
|
| 13 |
+
# 创建Gradio界面
|
| 14 |
+
iface = gr.Interface(fn=classify_text, inputs="text", outputs="json")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# 启动Gradio界面
|
| 17 |
+
iface.launch()
|