Spaces:
Running
Running
Update mapp.py
Browse files
mapp.py
CHANGED
@@ -1,37 +1,22 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
""
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
""
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
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)
|
|
|
1 |
+
from huggingface_hub import MCPClient
|
2 |
+
|
3 |
+
# Use Ollama via its OpenAI-compatible endpoint
|
4 |
+
client = MCPClient(
|
5 |
+
provider="openai",
|
6 |
+
base_url="http://localhost:11434/v1",
|
7 |
+
model="devstral", # or your custom Ollama model name
|
8 |
+
api_key="ollama" # any non-empty string is accepted by Ollama
|
9 |
+
)
|
10 |
+
|
11 |
+
# Attach Playwright MCP (local stdio server)
|
12 |
+
client.add_mcp_server(
|
13 |
+
type="stdio",
|
14 |
+
command="npx",
|
15 |
+
args=["@playwright/mcp@latest"]
|
16 |
+
)
|
17 |
+
|
18 |
+
# Run a single tool-using turn
|
19 |
+
for chunk in client.process_single_turn_with_tools(
|
20 |
+
messages=[{"role": "user", "content": "Open the browser and list the titles on https://news.ycombinator.com"}]
|
21 |
+
):
|
22 |
+
print(chunk)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|