Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
from duckduckgo_search import DDGS
|
3 |
-
#from huggingface_hub import InferenceClient
|
4 |
|
5 |
# Simulated knowledge base
|
6 |
TROUBLESHOOTING_KB = {
|
7 |
"wifi not working": [
|
8 |
-
"
|
9 |
"Restart your router.",
|
10 |
-
"
|
11 |
-
"
|
12 |
],
|
13 |
"computer is slow": [
|
14 |
-
"Close
|
15 |
-
"
|
16 |
"Restart your computer.",
|
17 |
-
"Check for
|
18 |
]
|
19 |
}
|
20 |
|
21 |
# Tool: search_knowledge_base
|
22 |
-
def search_knowledge_base(problem: str):
|
23 |
problem = problem.lower()
|
24 |
for key in TROUBLESHOOTING_KB:
|
25 |
if key in problem:
|
@@ -27,7 +26,7 @@ def search_knowledge_base(problem: str):
|
|
27 |
return ["No matching solution found in the knowledge base."]
|
28 |
|
29 |
# Tool: search_web
|
30 |
-
def search_web(query: str):
|
31 |
results = []
|
32 |
with DDGS() as ddgs:
|
33 |
for r in ddgs.text(query, max_results=3):
|
@@ -38,26 +37,37 @@ def search_web(query: str):
|
|
38 |
})
|
39 |
return results
|
40 |
|
41 |
-
#
|
42 |
-
def
|
43 |
-
return f"Stub for visiting {url}"
|
44 |
-
|
45 |
-
# Optional Tool: format_response
|
46 |
-
def format_response(text: str):
|
47 |
return f"🛠️ Troubleshooting Steps:\n{text}"
|
48 |
|
49 |
-
# Gradio
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
62 |
|
63 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from duckduckgo_search import DDGS
|
|
|
3 |
|
4 |
# Simulated knowledge base
|
5 |
TROUBLESHOOTING_KB = {
|
6 |
"wifi not working": [
|
7 |
+
"Ensure your router is powered on.",
|
8 |
"Restart your router.",
|
9 |
+
"Verify your device is connected to the correct Wi-Fi network.",
|
10 |
+
"Attempt to connect another device to determine if the issue is device-specific."
|
11 |
],
|
12 |
"computer is slow": [
|
13 |
+
"Close unnecessary applications.",
|
14 |
+
"Run a virus scan using your antivirus software.",
|
15 |
"Restart your computer.",
|
16 |
+
"Check for and install available system updates."
|
17 |
]
|
18 |
}
|
19 |
|
20 |
# Tool: search_knowledge_base
|
21 |
+
def search_knowledge_base(problem: str) -> list[str]:
|
22 |
problem = problem.lower()
|
23 |
for key in TROUBLESHOOTING_KB:
|
24 |
if key in problem:
|
|
|
26 |
return ["No matching solution found in the knowledge base."]
|
27 |
|
28 |
# Tool: search_web
|
29 |
+
def search_web(query: str) -> list[dict]:
|
30 |
results = []
|
31 |
with DDGS() as ddgs:
|
32 |
for r in ddgs.text(query, max_results=3):
|
|
|
37 |
})
|
38 |
return results
|
39 |
|
40 |
+
# Tool: format_response
|
41 |
+
def format_response(text: str) -> str:
|
|
|
|
|
|
|
|
|
42 |
return f"🛠️ Troubleshooting Steps:\n{text}"
|
43 |
|
44 |
+
# Create Gradio Interfaces for each tool
|
45 |
+
kb_interface = gr.Interface(
|
46 |
+
fn=search_knowledge_base,
|
47 |
+
inputs=gr.Textbox(label="Describe your problem"),
|
48 |
+
outputs=gr.JSON(label="Knowledge Base Steps"),
|
49 |
+
title="Knowledge Base Search",
|
50 |
+
description="Search for troubleshooting steps in the internal knowledge base."
|
51 |
+
)
|
52 |
|
53 |
+
web_interface = gr.Interface(
|
54 |
+
fn=search_web,
|
55 |
+
inputs=gr.Textbox(label="Enter search query"),
|
56 |
+
outputs=gr.JSON(label="Web Search Results"),
|
57 |
+
title="Web Search",
|
58 |
+
description="Perform a web search for additional troubleshooting information."
|
59 |
+
)
|
60 |
|
61 |
+
format_interface = gr.Interface(
|
62 |
+
fn=format_response,
|
63 |
+
inputs=gr.Textbox(label="Response Text"),
|
64 |
+
outputs=gr.Textbox(label="Formatted Response"),
|
65 |
+
title="Response Formatter",
|
66 |
+
description="Format the troubleshooting steps for better readability."
|
67 |
+
)
|
68 |
|
69 |
+
# Launch the interfaces with MCP server enabled
|
70 |
+
if __name__ == "__main__":
|
71 |
+
kb_interface.launch(mcp_server=True)
|
72 |
+
web_interface.launch(mcp_server=True)
|
73 |
+
format_interface.launch(mcp_server=True)
|