Test / app.py
Sadem-12's picture
Create app.py
37bcf03 verified
raw
history blame contribute delete
814 Bytes
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()