File size: 520 Bytes
022803a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline

sentiment_pipeline = pipeline(
    "sentiment-analysis",
    model="distilbert-base-uncased-finetuned-sst-2-english"
)

def analyze(text):
    result = sentiment_pipeline(text)[0]
    label = result["label"]
    score = result["score"]
    return f"{label} ({score:.2%} confidence)"

demo = gr.Interface(
    fn=analyze,
    inputs=gr.Textbox(placeholder="Type something..."),
    outputs=gr.Textbox(label="Result"),
    title="Sentiment Analyzer"
)

demo.launch()