Manavraj commited on
Commit
69aae5c
·
verified ·
1 Parent(s): e8441bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -27
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
- "Check if your router is turned on.",
9
  "Restart your router.",
10
- "Ensure your device is connected to the correct Wi-Fi network.",
11
- "Try connecting another device to determine if the issue is with your device or the network."
12
  ],
13
  "computer is slow": [
14
- "Close unused applications.",
15
- "Check for viruses using antivirus software.",
16
  "Restart your computer.",
17
- "Check for available updates and install them."
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
- # Optional Tool: visit_webpage
42
- def visit_webpage(url: str):
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 interface
50
- with gr.Blocks() as demo:
51
- gr.Markdown("# 🧠 Troubleshooting MCP Server")
 
 
 
 
 
52
 
53
- with gr.Row():
54
- kb_input = gr.Textbox(label="Describe your problem")
55
- kb_output = gr.JSON(label="Knowledge Base Steps")
56
- gr.Button("Search KB").click(search_knowledge_base, inputs=kb_input, outputs=kb_output)
 
 
 
57
 
58
- with gr.Row():
59
- web_input = gr.Textbox(label="Enter search query")
60
- web_output = gr.JSON(label="Web Search Results")
61
- gr.Button("Search Web").click(search_web, inputs=web_input, outputs=web_output)
 
 
 
62
 
63
- demo.launch(mcp_server=True)
 
 
 
 
 
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)