File size: 855 Bytes
290554d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32


# Use a pipeline as a high-level helper
from transformers import pipeline
import torch
import gradio as gr


sentiment_Analyzer = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")



def analyzer(text):
    output = (sentiment_Analyzer(text))[0]
    label = output['label']
    score = output['score']
    return label,score

# Create the Gradio interface
interface = gr.Interface(
    fn=analyzer,
    inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
    outputs=[
        gr.Textbox(label="Sentiment Label", placeholder="Label will appear here..."),
        gr.Number(label="Confidence Score")
    ],
    title="Sentiment Analyzer",
    description="Enter text to analyze its sentiment (positive/negative) and get the confidence score."
)

# Launch the Gradio interface
interface.launch()