centroIA's picture
app.py
5c676de verified
import gradio as gr
from transformers import pipeline
# Cargar el pipeline de Hugging Face para an谩lisis de sentimientos
sentiment_pipeline = pipeline("sentiment-analysis")
# Funci贸n para procesar el texto y devolver el sentimiento
def analyze_sentiment(input_text):
result = sentiment_pipeline(input_text)[0]
sentiment = result["label"]
confidence = result["score"]
return f"Sentiment: {sentiment}, Confidence: {confidence:.2f}"
# Configuraci贸n de la app Gradio
iface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(label="Enter your text for Sentiment Analysis"),
outputs=gr.Textbox(label="Sentiment Result"),
title="Sentiment Analysis API",
description="This API analyzes the sentiment of your text input. It returns if the sentiment is POSITIVE, NEGATIVE, or NEUTRAL along with a confidence score."
)
# Lanzar la app
iface.launch()