File size: 647 Bytes
9628f3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline
import gradio as gr

# Cargar modelo de Hugging Face
sentiment_pipeline = pipeline(
    "sentiment-analysis",
    model="distilbert-base-uncased-finetuned-sst-2-english"
)

def sentiment_analysis(text: str) -> dict:
    result = sentiment_pipeline(text)[0]
    return {
        "sentiment": result["label"],
        "confidence": round(result["score"], 4)
    }

demo = gr.Interface(
    fn=sentiment_analysis,
    inputs=gr.Textbox(placeholder="Enter text..."),
    outputs=gr.JSON(),
    title="LLM-based Sentiment Analysis"
)

if __name__ == "__main__":
    demo.launch(mcp_server=True)