Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- requirements.txt +4 -0
- server.py +25 -0
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# requirements.txt
|
| 2 |
+
gradio[mcp]
|
| 3 |
+
transformers
|
| 4 |
+
torch
|
server.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Cargar modelo de Hugging Face
|
| 5 |
+
sentiment_pipeline = pipeline(
|
| 6 |
+
"sentiment-analysis",
|
| 7 |
+
model="distilbert-base-uncased-finetuned-sst-2-english"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
def sentiment_analysis(text: str) -> dict:
|
| 11 |
+
result = sentiment_pipeline(text)[0]
|
| 12 |
+
return {
|
| 13 |
+
"sentiment": result["label"],
|
| 14 |
+
"confidence": round(result["score"], 4)
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
demo = gr.Interface(
|
| 18 |
+
fn=sentiment_analysis,
|
| 19 |
+
inputs=gr.Textbox(placeholder="Enter text..."),
|
| 20 |
+
outputs=gr.JSON(),
|
| 21 |
+
title="LLM-based Sentiment Analysis"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
demo.launch(mcp_server=True)
|