Manavraj's picture
Update app.py
4c95634 verified
raw
history blame
1.92 kB
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()