Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,51 @@
|
|
1 |
-
|
|
|
|
|
2 |
|
3 |
-
# Your
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
#
|
12 |
-
agent = CodeAgent(
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
query = "My WiFi keeps disconnecting randomly. What can I do?"
|
16 |
-
response = agent.run(query)
|
17 |
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|