Spaces:
Runtime error
Runtime error
largo commited on
Commit ·
b903474
1
Parent(s): 833b609
Initial commit
Browse files- .continue/mcpServers/playwright-mcp.yaml +8 -0
- .continue/models/llama-max.yaml +12 -0
- .gitignore +3 -0
- README.md +12 -5
- app.py +37 -0
- gradio-client.py +26 -0
- requirements.txt +2 -0
.continue/mcpServers/playwright-mcp.yaml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Playwright mcpServer
|
| 2 |
+
version: 0.0.1
|
| 3 |
+
schema: v1
|
| 4 |
+
mcpServers:
|
| 5 |
+
- name: Browser search
|
| 6 |
+
command: npx
|
| 7 |
+
args:
|
| 8 |
+
- "@playwright/mcp@latest"
|
.continue/models/llama-max.yaml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Ollama Llama model
|
| 2 |
+
version: 0.0.1
|
| 3 |
+
schema: v1
|
| 4 |
+
models:
|
| 5 |
+
- provider: ollama
|
| 6 |
+
model: llama3.1:8b
|
| 7 |
+
defaultCompletionOptions:
|
| 8 |
+
contextLength: 128000
|
| 9 |
+
name: a llama3.1:8b max
|
| 10 |
+
roles:
|
| 11 |
+
- chat
|
| 12 |
+
- edit
|
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules/
|
| 2 |
+
__pycache__/
|
| 3 |
+
.tm
|
README.md
CHANGED
|
@@ -1,13 +1,20 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.34.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Mcp Sentiment
|
| 3 |
+
emoji: 🐢
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.34.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
short_description: Unit 2 MCP course
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 15 |
+
|
| 16 |
+
# Deps
|
| 17 |
+
|
| 18 |
+
```bash
|
| 19 |
+
pip install "smolagents[mcp]" "gradio[mcp]" mcp fastmcp
|
| 20 |
+
```
|
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)
|
gradio-client.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
from smolagents import InferenceClientModel, CodeAgent, MCPClient
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
mcp_client = MCPClient(
|
| 9 |
+
{"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"}
|
| 10 |
+
)
|
| 11 |
+
tools = mcp_client.get_tools()
|
| 12 |
+
|
| 13 |
+
model = InferenceClientModel(token=os.getenv("HF_HUB_TOKEN"))
|
| 14 |
+
agent = CodeAgent(tools=[*tools], model=model, additional_authorized_imports=["json", "ast", "urllib", "base64"])
|
| 15 |
+
|
| 16 |
+
demo = gr.ChatInterface(
|
| 17 |
+
fn=lambda message, history: str(agent.run(message)),
|
| 18 |
+
type="messages",
|
| 19 |
+
examples=["Analyze the sentiment of the following text 'This is awesome'"],
|
| 20 |
+
title="Agent with MCP Tools",
|
| 21 |
+
description="This is a simple agent that uses MCP tools to answer questions.",
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
demo.launch()
|
| 25 |
+
finally:
|
| 26 |
+
mcp_client.disconnect()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio[mcp]
|
| 2 |
+
textblob
|