Spaces:
Sleeping
Sleeping
Commit ·
b7c0594
1
Parent(s): 1cf2b92
building the agent toekn 3
Browse files
app.py
CHANGED
|
@@ -11,8 +11,9 @@ class SentimentAnalysisTool(Tool):
|
|
| 11 |
"""
|
| 12 |
name = "sentiment_analysis"
|
| 13 |
description = """
|
| 14 |
-
Analyze the sentiment of
|
| 15 |
-
|
|
|
|
| 16 |
This tool connects to the MCP sentiment analysis server.
|
| 17 |
"""
|
| 18 |
|
|
@@ -220,7 +221,26 @@ def chat_with_agent(message, history, request: gr.Request):
|
|
| 220 |
try:
|
| 221 |
# Run the agent and get the response
|
| 222 |
result = agent.run(message)
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
except Exception as e:
|
| 225 |
return f"Error: {str(e)}"
|
| 226 |
|
|
@@ -230,7 +250,7 @@ demo = gr.ChatInterface(
|
|
| 230 |
fn=chat_with_agent,
|
| 231 |
title="MCP Sentiment Analysis Agent",
|
| 232 |
description="Chat with an AI agent that can analyze sentiment using the MCP sentiment analysis server.",
|
| 233 |
-
chatbot=gr.Chatbot(layout="bubble", show_copy_button=True),
|
| 234 |
type="messages"
|
| 235 |
)
|
| 236 |
|
|
|
|
| 11 |
"""
|
| 12 |
name = "sentiment_analysis"
|
| 13 |
description = """
|
| 14 |
+
Analyze the sentiment of text to determine if it's positive, negative, or neutral.
|
| 15 |
+
Use this tool when the user asks about sentiment, emotion, feeling, or opinion in text.
|
| 16 |
+
Returns polarity score (-1 to 1), subjectivity (0 to 1), and assessment (positive/negative/neutral).
|
| 17 |
This tool connects to the MCP sentiment analysis server.
|
| 18 |
"""
|
| 19 |
|
|
|
|
| 221 |
try:
|
| 222 |
# Run the agent and get the response
|
| 223 |
result = agent.run(message)
|
| 224 |
+
|
| 225 |
+
# Convert result to string if it's not already
|
| 226 |
+
if isinstance(result, dict):
|
| 227 |
+
# Format dictionary results nicely
|
| 228 |
+
if "polarity" in result and "subjectivity" in result and "assessment" in result:
|
| 229 |
+
formatted_result = f"""Sentiment Analysis Results:
|
| 230 |
+
- **Polarity**: {result['polarity']} (range: -1 to 1)
|
| 231 |
+
- **Subjectivity**: {result['subjectivity']} (range: 0 to 1)
|
| 232 |
+
- **Assessment**: {result['assessment'].upper()}"""
|
| 233 |
+
return formatted_result
|
| 234 |
+
else:
|
| 235 |
+
# Format other dictionaries as JSON
|
| 236 |
+
import json
|
| 237 |
+
return json.dumps(result, indent=2)
|
| 238 |
+
elif isinstance(result, (list, tuple)):
|
| 239 |
+
# Convert lists/tuples to string
|
| 240 |
+
return str(result)
|
| 241 |
+
else:
|
| 242 |
+
# Already a string or other type that can be converted
|
| 243 |
+
return str(result)
|
| 244 |
except Exception as e:
|
| 245 |
return f"Error: {str(e)}"
|
| 246 |
|
|
|
|
| 250 |
fn=chat_with_agent,
|
| 251 |
title="MCP Sentiment Analysis Agent",
|
| 252 |
description="Chat with an AI agent that can analyze sentiment using the MCP sentiment analysis server.",
|
| 253 |
+
chatbot=gr.Chatbot(layout="bubble", show_copy_button=True, type="messages"),
|
| 254 |
type="messages"
|
| 255 |
)
|
| 256 |
|