Lazer5641's picture
Create app.py
edabb58 verified
Raw History Blame Contribute Delete
785 Bytes
import gradio as gr
from transformers import pipeline
# Initialize sentiment analysis pipeline
sentiment_analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
def analyze_sentiment(text):
if not text.strip():
return "Please enter text to analyze."
result = sentiment_analyzer(text)[0]
return f"Sentiment: {result['label']} (Confidence: {result['score']:.2f})"
# Gradio interface
demo = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(label="Enter text", placeholder="Type your text here..."),
outputs=gr.Textbox(label="Sentiment Result"),
title="Sentiment Analysis App",
description="Analyze the sentiment of your text (positive or negative)."
)
if __name__ == "__main__":
demo.launch()