File size: 801 Bytes
ea8846a
 
 
 
 
e865924
 
 
 
ea8846a
 
e865924
 
 
 
 
 
 
 
 
 
ea8846a
 
e865924
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from transformers import pipeline
# Load the sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")
def analyze_sentiment(text):
    result = sentiment_pipeline(text)[0]
    label = result["label"]
    score = result["score"]
    return f"Sentiment: {label}\nConfidence: {score:.2f}"
# Create the Gradio interface
iface = gr.Interface(
    fn=analyze_sentiment,
    inputs=gr.Textbox(placeholder="Enter text to analyze..."),
    outputs=gr.Textbox(),
    title="Sentiment Analysis App",
    description="Enter a sentence to determine its sentiment (positive or negative).",
    examples=[
    ["I love this product! It's amazing!"],
    ["I am very disappointed with the service."]
    ]
    )
# Launch the app
if __name__ == "__main__":
    iface.launch()