File size: 1,923 Bytes
4c95634
 
 
957adf6
4c95634
 
957adf6
4c95634
 
 
 
 
 
 
 
 
a3f7cf5
4c95634
 
 
 
 
957adf6
4c95634
957adf6
4c95634
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr
import requests
from smolagents import CodeAgent

# Your HF Space URL - Replace with your actual space URL
HF_SPACE_URL = "https://Manavraj-Troubleshoot_MCP.hf.space"

def call_mcp_server(message):
    """Call your MCP server and let it handle tool selection"""
    try:
        # Call your server's main interface or create a unified endpoint
        response = requests.post(f"{HF_SPACE_URL}/api/predict", 
                               json={"data": [message], "fn_index": 0})
        return response.json().get("data", ["No response"])[0]
    except Exception as e:
        return f"MCP server error: {str(e)}"

# Initialize CodeAgent 
agent = CodeAgent(
    tools=[],  # No tools needed - server handles everything
    model="microsoft/DialoGPT-medium",
    system_prompt="""You are a Technical Support AI Agent connected to an MCP server.

Your goal is to help users with technical problems by routing their requests to the appropriate server tools and providing clear, helpful responses.

The MCP server has knowledge base search, web search, and response formatting capabilities. Simply process user queries and provide helpful technical support."""
)

def chat_interface(message, history):
    """Route user message to MCP server"""
    mcp_response = call_mcp_server(message)
    try:
        final_response = agent.run(f"User asked: {message}\nMCP Server response: {mcp_response}\nProvide a helpful response:")
        return final_response
    except:
        return mcp_response  # Fallback to direct MCP response

# Create Gradio interface
demo = gr.ChatInterface(
    fn=chat_interface,
    title="🔧 MCP Technical Support Agent", 
    description="Technical support powered by MCP server tools",
    examples=[
        "I have a wifi connection problem",
        "My screen keeps flickering",
        "Search for latest tech news"
    ]
)

if __name__ == "__main__":
    demo.launch()