Spaces:
Runtime error
Runtime error
import gradio as gr | |
# --- Tool: Simulated troubleshooting knowledge base --- | |
def search_knowledge_base(issue: str) -> str: | |
if "wifi" in issue.lower(): | |
return "Check if your router is powered on. Restart your router. Try connecting again." | |
elif "screen" in issue.lower(): | |
return "Adjust display cable. Update graphics drivers. Restart the system." | |
return "No predefined solution found in the knowledge base." | |
# --- Tool: Simulated web search (basic dummy) --- | |
def search_web(query: str) -> str: | |
return f"(Simulated Web Result) Top search result for '{query}'." | |
# --- Tool: Format output into step-by-step troubleshooting response --- | |
def format_response(raw_steps: str) -> str: | |
steps = raw_steps.split(". ") | |
steps = [f"{i+1}. {step.strip('.')}" for i, step in enumerate(steps) if step.strip()] | |
return "\n".join(steps) | |
# Register each tool with a separate interface | |
tools = [ | |
gr.Interface(fn=search_knowledge_base, | |
inputs="text", | |
outputs="text", | |
title="Knowledge Base Search", | |
description="Search for predefined troubleshooting instructions.", | |
name="search_knowledge_base"), | |
gr.Interface(fn=search_web, | |
inputs="text", | |
outputs="text", | |
title="Web Search Tool", | |
description="Fetch dynamic info from the web (simulated).", | |
name="search_web"), | |
gr.Interface(fn=format_response, | |
inputs="text", | |
outputs="text", | |
title="Response Formatter", | |
description="Format the raw instructions into steps.", | |
name="format_response") | |
] | |
# Launch all tools under one MCP server | |
if __name__ == "__main__": | |
gr.mount_gradio_apps(tools).launch() | |