File size: 2,386 Bytes
140fcff
f379bec
 
 
 
 
69aae5c
f379bec
69aae5c
 
140fcff
f379bec
69aae5c
 
f379bec
69aae5c
f379bec
 
 
 
69aae5c
f379bec
 
 
 
 
 
 
69aae5c
f379bec
 
 
 
 
 
 
 
 
 
69aae5c
 
f379bec
 
69aae5c
 
 
 
 
 
 
 
f379bec
69aae5c
 
 
 
 
 
 
f379bec
69aae5c
 
 
 
 
 
 
f379bec
69aae5c
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import gradio as gr
from duckduckgo_search import DDGS

# Simulated knowledge base
TROUBLESHOOTING_KB = {
    "wifi not working": [
        "Ensure your router is powered on.",
        "Restart your router.",
        "Verify your device is connected to the correct Wi-Fi network.",
        "Attempt to connect another device to determine if the issue is device-specific."
    ],
    "computer is slow": [
        "Close unnecessary applications.",
        "Run a virus scan using your antivirus software.",
        "Restart your computer.",
        "Check for and install available system updates."
    ]
}

# Tool: search_knowledge_base
def search_knowledge_base(problem: str) -> list[str]:
    problem = problem.lower()
    for key in TROUBLESHOOTING_KB:
        if key in problem:
            return TROUBLESHOOTING_KB[key]
    return ["No matching solution found in the knowledge base."]

# Tool: search_web
def search_web(query: str) -> list[dict]:
    results = []
    with DDGS() as ddgs:
        for r in ddgs.text(query, max_results=3):
            results.append({
                "title": r["title"],
                "body": r["body"],
                "href": r["href"]
            })
    return results

# Tool: format_response
def format_response(text: str) -> str:
    return f"🛠️ Troubleshooting Steps:\n{text}"

# Create Gradio Interfaces for each tool
kb_interface = gr.Interface(
    fn=search_knowledge_base,
    inputs=gr.Textbox(label="Describe your problem"),
    outputs=gr.JSON(label="Knowledge Base Steps"),
    title="Knowledge Base Search",
    description="Search for troubleshooting steps in the internal knowledge base."
)

web_interface = gr.Interface(
    fn=search_web,
    inputs=gr.Textbox(label="Enter search query"),
    outputs=gr.JSON(label="Web Search Results"),
    title="Web Search",
    description="Perform a web search for additional troubleshooting information."
)

format_interface = gr.Interface(
    fn=format_response,
    inputs=gr.Textbox(label="Response Text"),
    outputs=gr.Textbox(label="Formatted Response"),
    title="Response Formatter",
    description="Format the troubleshooting steps for better readability."
)

# Launch the interfaces with MCP server enabled
if __name__ == "__main__":
    kb_interface.launch(mcp_server=True)
    web_interface.launch(mcp_server=True)
    format_interface.launch(mcp_server=True)