Manavraj's picture
MCP Server 1st launch
f379bec verified
raw
history blame
2.04 kB
import gradio as gr
from duckduckgo_search import DDGS
#from huggingface_hub import InferenceClient
# Simulated knowledge base
TROUBLESHOOTING_KB = {
"wifi not working": [
"Check if your router is turned on.",
"Restart your router.",
"Ensure your device is connected to the correct Wi-Fi network.",
"Try connecting another device to determine if the issue is with your device or the network."
],
"computer is slow": [
"Close unused applications.",
"Check for viruses using antivirus software.",
"Restart your computer.",
"Check for available updates and install them."
]
}
# Tool: search_knowledge_base
def search_knowledge_base(problem: str):
problem = problem.lower()
for key in TROUBLESHOOTING_KB:
if key in problem:
return TROUBLESHOOTING_KB[key]
return ["No matching solution found in the knowledge base."]
# Tool: search_web
def search_web(query: str):
results = []
with DDGS() as ddgs:
for r in ddgs.text(query, max_results=3):
results.append({
"title": r["title"],
"body": r["body"],
"href": r["href"]
})
return results
# Optional Tool: visit_webpage
def visit_webpage(url: str):
return f"Stub for visiting {url}"
# Optional Tool: format_response
def format_response(text: str):
return f"🛠️ Troubleshooting Steps:\n{text}"
# Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# 🧠 Troubleshooting MCP Server")
with gr.Row():
kb_input = gr.Textbox(label="Describe your problem")
kb_output = gr.JSON(label="Knowledge Base Steps")
gr.Button("Search KB").click(search_knowledge_base, inputs=kb_input, outputs=kb_output)
with gr.Row():
web_input = gr.Textbox(label="Enter search query")
web_output = gr.JSON(label="Web Search Results")
gr.Button("Search Web").click(search_web, inputs=web_input, outputs=web_output)
demo.launch(mcp_server=True)