Manavraj commited on
Commit
4c95634
·
verified ·
1 Parent(s): e0e8a9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -14
app.py CHANGED
@@ -1,19 +1,51 @@
1
- from smolagents import Tool, CodeAgent
 
 
2
 
3
- # Your MCP server base URL on Hugging Face Spaces
4
- MCP_URL = "https://Manavraj-Troubleshoot_MCP.hf.space"
5
 
6
- # Load tools from your MCP server
7
- kb_tool = Tool.from_mcp(MCP_URL, name="search_knowledge_base")
8
- web_tool = Tool.from_mcp(MCP_URL, name="search_web")
9
- format_tool = Tool.from_mcp(MCP_URL, name="format_response")
 
 
 
 
 
10
 
11
- # Create agent with all three tools
12
- agent = CodeAgent(tools=[kb_tool, web_tool, format_tool])
 
 
 
13
 
14
- # Run example input
15
- query = "My WiFi keeps disconnecting randomly. What can I do?"
16
- response = agent.run(query)
17
 
18
- print("Agent's Troubleshooting Response:")
19
- print(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ from smolagents import CodeAgent
4
 
5
+ # Your HF Space URL - Replace with your actual space URL
6
+ HF_SPACE_URL = "https://Manavraj-Troubleshoot_MCP.hf.space"
7
 
8
+ def call_mcp_server(message):
9
+ """Call your MCP server and let it handle tool selection"""
10
+ try:
11
+ # Call your server's main interface or create a unified endpoint
12
+ response = requests.post(f"{HF_SPACE_URL}/api/predict",
13
+ json={"data": [message], "fn_index": 0})
14
+ return response.json().get("data", ["No response"])[0]
15
+ except Exception as e:
16
+ return f"MCP server error: {str(e)}"
17
 
18
+ # Initialize CodeAgent
19
+ agent = CodeAgent(
20
+ tools=[], # No tools needed - server handles everything
21
+ model="microsoft/DialoGPT-medium",
22
+ system_prompt="""You are a Technical Support AI Agent connected to an MCP server.
23
 
24
+ Your goal is to help users with technical problems by routing their requests to the appropriate server tools and providing clear, helpful responses.
 
 
25
 
26
+ The MCP server has knowledge base search, web search, and response formatting capabilities. Simply process user queries and provide helpful technical support."""
27
+ )
28
+
29
+ def chat_interface(message, history):
30
+ """Route user message to MCP server"""
31
+ mcp_response = call_mcp_server(message)
32
+ try:
33
+ final_response = agent.run(f"User asked: {message}\nMCP Server response: {mcp_response}\nProvide a helpful response:")
34
+ return final_response
35
+ except:
36
+ return mcp_response # Fallback to direct MCP response
37
+
38
+ # Create Gradio interface
39
+ demo = gr.ChatInterface(
40
+ fn=chat_interface,
41
+ title="🔧 MCP Technical Support Agent",
42
+ description="Technical support powered by MCP server tools",
43
+ examples=[
44
+ "I have a wifi connection problem",
45
+ "My screen keeps flickering",
46
+ "Search for latest tech news"
47
+ ]
48
+ )
49
+
50
+ if __name__ == "__main__":
51
+ demo.launch()