File size: 887 Bytes
5c676de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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()