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()