Spaces:
Runtime error
Runtime error
NicolaiBure commited on
Commit ·
060bf04
0
Parent(s):
Clean start without venv
Browse files- .gitignore +1 -0
- README.md +31 -0
- app.py +37 -0
- requirements.txt +2 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
venv/
|
README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: MCP Sentiment
|
| 3 |
+
emoji: 💬
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: "4.25.0"
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# MCP Sentiment Analysis
|
| 13 |
+
|
| 14 |
+
Este Space demuestra un ejemplo básico de análisis de sentimiento utilizando Gradio y TextBlob, como parte del curso de MCP (Multimodal Chain of Thought Prompting).
|
| 15 |
+
|
| 16 |
+
## 🧠 ¿Cómo funciona?
|
| 17 |
+
|
| 18 |
+
- Introduce una frase o texto.
|
| 19 |
+
- El sistema analiza el sentimiento con TextBlob.
|
| 20 |
+
- Devuelve una respuesta: "Positive" o "Negative".
|
| 21 |
+
|
| 22 |
+
## 📦 Requisitos (ya configurados automáticamente)
|
| 23 |
+
|
| 24 |
+
gradio[mcp]
|
| 25 |
+
textblob
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
## 🛠️ Autor
|
| 29 |
+
|
| 30 |
+
Espacio desarrollado por [NixBure](https://huggingface.co/NixBure) como parte del curso MCP.
|
| 31 |
+
# Reconstrucción
|
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from textblob import TextBlob
|
| 4 |
+
|
| 5 |
+
def sentiment_analysis(text: str) -> str:
|
| 6 |
+
"""
|
| 7 |
+
Analyze the sentiment of the given text.
|
| 8 |
+
|
| 9 |
+
Args:
|
| 10 |
+
text (str): The text to analyze
|
| 11 |
+
|
| 12 |
+
Returns:
|
| 13 |
+
str: A JSON string containing polarity, subjectivity, and assessment
|
| 14 |
+
"""
|
| 15 |
+
blob = TextBlob(text)
|
| 16 |
+
sentiment = blob.sentiment
|
| 17 |
+
|
| 18 |
+
result = {
|
| 19 |
+
"polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
|
| 20 |
+
"subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
|
| 21 |
+
"assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
return json.dumps(result)
|
| 25 |
+
|
| 26 |
+
# Create the Gradio interface
|
| 27 |
+
demo = gr.Interface(
|
| 28 |
+
fn=sentiment_analysis,
|
| 29 |
+
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
|
| 30 |
+
outputs=gr.Textbox(), # Changed from gr.JSON() to gr.Textbox()
|
| 31 |
+
title="Text Sentiment Analysis",
|
| 32 |
+
description="Analyze the sentiment of text using TextBlob"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Launch the interface and MCP server
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio[mcp]==4.44.1
|
| 2 |
+
textblob
|