Manavraj commited on
Commit
4023d78
·
verified ·
1 Parent(s): 8abedb7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -48
app.py CHANGED
@@ -1,31 +1,28 @@
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:
25
- return TROUBLESHOOTING_KB[key]
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:
@@ -37,37 +34,36 @@ def search_web(query: str) -> list[dict]:
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)
 
1
  import gradio as gr
2
  from duckduckgo_search import DDGS
3
 
4
+ # Tool 1: Knowledge Base Search
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def search_knowledge_base(problem: str) -> list[str]:
6
  problem = problem.lower()
7
+ KB = {
8
+ "wifi not working": [
9
+ "Check if the router is on.",
10
+ "Restart the router.",
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 2: Web Search
26
  def search_web(query: str) -> list[dict]:
27
  results = []
28
  with DDGS() as ddgs:
 
34
  })
35
  return results
36
 
37
+ # Tool 3: Format response
38
  def format_response(text: str) -> str:
39
+ return f"🛠️ Suggested Steps:\n{text}"
 
 
 
 
 
 
 
 
 
40
 
41
+ # Combine tools into a single unified function
42
+ def toolbox(tool_selector, input_text):
43
+ if tool_selector == "search_knowledge_base":
44
+ return search_knowledge_base(input_text)
45
+ elif tool_selector == "search_web":
46
+ return search_web(input_text)
47
+ elif tool_selector == "format_response":
48
+ return format_response(input_text)
49
+ else:
50
+ return "Invalid tool selected."
51
 
52
+ # Define Interface
53
+ demo = gr.Interface(
54
+ fn=toolbox,
55
+ inputs=[
56
+ gr.Dropdown(
57
+ ["search_knowledge_base", "search_web", "format_response"],
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
+ # Launch with MCP server enabled
68
  if __name__ == "__main__":
69
+ demo.launch(mcp_server=True)