william1324 commited on
Commit
2cc4dc9
·
verified ·
1 Parent(s): 19e115d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ classifier = pipeline("sentiment-analysis")
5
+
6
+ def analyze(text):
7
+ result = classifier(text)[0]
8
+ label = result["label"]
9
+ score = round(result["score"], 3)
10
+ return f"情緒:{label}\n信心分數:{score}"
11
+
12
+ demo = gr.Interface(fn=analyze,
13
+ inputs=gr.Textbox(label="輸入文字"),
14
+ outputs="text",
15
+ title="情緒分析器",
16
+ description="輸入一段文字,判斷其情緒為 Positive 或 Negative")
17
+
18
+ demo.launch()