Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,69 +1,47 @@
|
|
1 |
import gradio as gr
|
2 |
-
from duckduckgo_search import DDGS
|
3 |
|
4 |
-
# Tool
|
5 |
-
def search_knowledge_base(
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
"Check if your device is connected to the right network."
|
12 |
-
],
|
13 |
-
"computer is slow": [
|
14 |
-
"Close unused programs.",
|
15 |
-
"Run antivirus scan.",
|
16 |
-
"Restart the computer.",
|
17 |
-
"Update your OS."
|
18 |
-
]
|
19 |
-
}
|
20 |
-
for key in KB:
|
21 |
-
if key in problem:
|
22 |
-
return KB[key]
|
23 |
-
return ["No matching solution found in the knowledge base."]
|
24 |
|
25 |
-
# Tool
|
26 |
-
def search_web(query: str) ->
|
27 |
-
|
28 |
-
with DDGS() as ddgs:
|
29 |
-
for r in ddgs.text(query, max_results=3):
|
30 |
-
results.append({
|
31 |
-
"title": r["title"],
|
32 |
-
"body": r["body"],
|
33 |
-
"href": r["href"]
|
34 |
-
})
|
35 |
-
return results
|
36 |
|
37 |
-
# Tool
|
38 |
-
def format_response(
|
39 |
-
|
|
|
|
|
40 |
|
41 |
-
#
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
else:
|
50 |
-
return "Invalid tool selected."
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
label="Tool Selector"
|
59 |
-
),
|
60 |
-
gr.Textbox(label="Input Text")
|
61 |
-
],
|
62 |
-
outputs=gr.JSON(label="Output"),
|
63 |
-
title="Troubleshooting MCP Server",
|
64 |
-
description="Select a tool and provide input."
|
65 |
-
)
|
66 |
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
if __name__ == "__main__":
|
69 |
-
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
+
# --- Tool: Simulated troubleshooting knowledge base ---
|
4 |
+
def search_knowledge_base(issue: str) -> str:
|
5 |
+
if "wifi" in issue.lower():
|
6 |
+
return "Check if your router is powered on. Restart your router. Try connecting again."
|
7 |
+
elif "screen" in issue.lower():
|
8 |
+
return "Adjust display cable. Update graphics drivers. Restart the system."
|
9 |
+
return "No predefined solution found in the knowledge base."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# --- Tool: Simulated web search (basic dummy) ---
|
12 |
+
def search_web(query: str) -> str:
|
13 |
+
return f"(Simulated Web Result) Top search result for '{query}'."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# --- Tool: Format output into step-by-step troubleshooting response ---
|
16 |
+
def format_response(raw_steps: str) -> str:
|
17 |
+
steps = raw_steps.split(". ")
|
18 |
+
steps = [f"{i+1}. {step.strip('.')}" for i, step in enumerate(steps) if step.strip()]
|
19 |
+
return "\n".join(steps)
|
20 |
|
21 |
+
# Register each tool with a separate interface
|
22 |
+
tools = [
|
23 |
+
gr.Interface(fn=search_knowledge_base,
|
24 |
+
inputs="text",
|
25 |
+
outputs="text",
|
26 |
+
title="Knowledge Base Search",
|
27 |
+
description="Search for predefined troubleshooting instructions.",
|
28 |
+
name="search_knowledge_base"),
|
|
|
|
|
29 |
|
30 |
+
gr.Interface(fn=search_web,
|
31 |
+
inputs="text",
|
32 |
+
outputs="text",
|
33 |
+
title="Web Search Tool",
|
34 |
+
description="Fetch dynamic info from the web (simulated).",
|
35 |
+
name="search_web"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
gr.Interface(fn=format_response,
|
38 |
+
inputs="text",
|
39 |
+
outputs="text",
|
40 |
+
title="Response Formatter",
|
41 |
+
description="Format the raw instructions into steps.",
|
42 |
+
name="format_response")
|
43 |
+
]
|
44 |
+
|
45 |
+
# Launch all tools under one MCP server
|
46 |
if __name__ == "__main__":
|
47 |
+
gr.mount_gradio_apps(tools).launch()
|