SiddanthEmani commited on
Commit
917171f
·
1 Parent(s): 46584ef

Added coding agent

Browse files
Files changed (6) hide show
  1. MCP-SentimentAnalysis +0 -1
  2. client.py +29 -0
  3. config.json +7 -0
  4. doc.md +11 -0
  5. mcp.json +11 -0
  6. requirements.txt +2 -0
MCP-SentimentAnalysis DELETED
@@ -1 +0,0 @@
1
- Subproject commit a93ff3758cf8e0b5c79a7796a46dea8ab993c127
 
 
client.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from mcp.client.stdio import StdioClient
4
+ from smolagents import ToolCollection, CodeAgent, InferenceClientModel
5
+ from smolagents.mcp_client import MCPClient
6
+
7
+ try:
8
+ mcp_client = MCPClient(
9
+ {
10
+ "url": "http://localhost:7860/gradio_api/mcp/sse",
11
+ }
12
+ )
13
+ tools = mcp_client.get_tools()
14
+ model = InferenceClientModel()
15
+ agent = CodeAgent(tools=[*tools], model=model)
16
+
17
+ demo = gr.ChatInterface(
18
+ fn=lambda message, history: str(agent.run(message)),
19
+ type="messages",
20
+ examples=["What is the capital of France?"],
21
+ title="Agent with Gradio and MCP",
22
+ description="Simple agent used for asking questions.",
23
+ messages=[],
24
+ theme="ocean"
25
+ )
26
+
27
+ demo.launch()
28
+ finally:
29
+ mcp_client.close()
config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "mcpServers": {
3
+ "mcp": {
4
+ "url": "http://localhost:7860/gradio_api/mcp/sse"
5
+ }
6
+ }
7
+ }
doc.md CHANGED
@@ -5,12 +5,23 @@
5
  - `textblob`
6
 
7
  ## File Structure
 
 
 
 
8
  ### server.py
9
  Main file to run the Gradio app.
10
  - Gradio interface with MCP server is launched
11
  - Input = Text from textbox
12
  - Output = JSON with sentiment analysis results (polarity, subjectivity, assessment)
13
 
 
 
 
 
 
 
 
14
  ## Functions
15
  1. `analyze_sentiment(text) -> dict`
16
 
 
5
  - `textblob`
6
 
7
  ## File Structure
8
+
9
+ ### app.py
10
+ App file for huggingface spaces to build the Gradio app.
11
+
12
  ### server.py
13
  Main file to run the Gradio app.
14
  - Gradio interface with MCP server is launched
15
  - Input = Text from textbox
16
  - Output = JSON with sentiment analysis results (polarity, subjectivity, assessment)
17
 
18
+ ### mcp.json
19
+ JSON file containing the MCP server configuration.
20
+ servers = mcp server (sse transport, url)
21
+
22
+ ### config.json
23
+ JSON file containing the list of MCP servers for the client to connect to.
24
+
25
  ## Functions
26
  1. `analyze_sentiment(text) -> dict`
27
 
mcp.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "servers": [
3
+ {
4
+ "name": "MCP Server",
5
+ "transport": {
6
+ "type": "sse",
7
+ "url": "http://localhost:7860/gradio_api/mcp/sse"
8
+ }
9
+ }
10
+ ]
11
+ }
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
  gradio[mcp]
 
 
2
  textblob
 
1
  gradio[mcp]
2
+ smolagents[mcp]
3
+ mcp
4
  textblob