dominguezdaniel's picture
Update app.py
1efae8b verified
import gradio as gr
from transformers import pipeline
# Specify the model and revision explicitly
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
revision = "af0f99b"
# Load the sentiment analysis pipeline with the specified model and revision
sentiment_pipeline = pipeline("sentiment-analysis", model=model_name, revision=revision)
def predict_sentiment(text):
"""
Predicts the sentiment of the input text.
Returns the label (POSITIVE/NEGATIVE) and the confidence score.
"""
result = sentiment_pipeline(text)[0]
label = result['label']
confidence = round(result['score'], 4)
return f"Sentiment: {label}, Confidence: {confidence}"
# Create a Gradio interface
interface = gr.Interface(fn=predict_sentiment,
inputs=gr.Textbox(lines=2, placeholder="Enter Text Here..."),
outputs="text",
title="Simple Text Sentiment Analysis",
description="A simple text sentiment analysis tool using Hugging Face's transformers.")
# Launch the application
interface.launch()