File size: 675 Bytes
fba9bc7
 
 
 
 
 
4b5b0a0
 
 
 
 
 
 
 
 
 
daa8b2d
4b5b0a0
 
fba9bc7
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr
from transformers import pipeline

sentiment = pipeline("sentiment-analysis")

def get_sentiment(input_text):
    result = sentiment(input_text)
    labels = [item['label'] for item in result]
    scores = [item['score'] for item in result]
    return labels, scores

demo = gr.Interface(
    fn=get_sentiment,
    inputs="text",
    outputs=[gr.Textbox(label="Label"), gr.Textbox(label="Score")],
    title = 'Sentiment Analysis Demo (情緒分析示範)',
    description = "Analyze the sentiment based on given input (positive or negative) 情緒分析",
    examples=[["I love Computational Chemistry."], ["This movie is terrible."]],
)

demo.launch()