Manavraj commited on
Commit
e0e8a9c
·
verified ·
1 Parent(s): 264bfd9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -75
app.py CHANGED
@@ -1,80 +1,19 @@
1
- import gradio as gr
2
- #from huggingface_hub import InferenceClient
3
- from smolagents import CodeAgent, Tool
4
 
 
 
5
 
6
- #client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
 
 
7
 
8
- # Initialize the agent
9
- agent = CodeAgent(
10
- tools=[search_kb_tool, search_web_tool, format_response_tool],
11
- system_prompt="""
12
- You are a Basic Troubleshooting Assistant.
13
- Understand the user's problem, attempt to resolve it using the knowledge base.
14
- If the knowledge base is insufficient, perform a web search.
15
- Provide clear, step-by-step instructions and confirm each step's outcome.
16
- """
17
- )
18
 
19
- # Run the agent
20
- while True:
21
- user_input = input("User: ")
22
- if user_input.lower() in ["exit", "quit"]:
23
- break
24
- response = agent.run(user_input)
25
- print("Agent:", response)
26
- ###############################################################
27
- """def respond(
28
- message,
29
- history: list[tuple[str, str]],
30
- system_message,
31
- max_tokens,
32
- temperature,
33
- top_p,
34
- ):
35
- messages = [{"role": "system", "content": system_message}]
36
 
37
- for val in history:
38
- if val[0]:
39
- messages.append({"role": "user", "content": val[0]})
40
- if val[1]:
41
- messages.append({"role": "assistant", "content": val[1]})
42
-
43
- messages.append({"role": "user", "content": message})
44
-
45
- response = ""
46
-
47
- for message in client.chat_completion(
48
- messages,
49
- max_tokens=max_tokens,
50
- stream=True,
51
- temperature=temperature,
52
- top_p=top_p,
53
- ):
54
- token = message.choices[0].delta.content
55
-
56
- response += token
57
- yield response
58
-
59
-
60
-
61
- demo = gr.ChatInterface(
62
- respond,
63
- additional_inputs=[
64
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
65
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
66
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
67
- gr.Slider(
68
- minimum=0.1,
69
- maximum=1.0,
70
- value=0.95,
71
- step=0.05,
72
- label="Top-p (nucleus sampling)",
73
- ),
74
- ],
75
- )
76
-
77
-
78
- if __name__ == "__main__":
79
- demo.launch()
80
- """
 
1
+ from smolagents import Tool, CodeAgent
 
 
2
 
3
+ # Your MCP server base URL on Hugging Face Spaces
4
+ MCP_URL = "https://Manavraj-Troubleshoot_MCP.hf.space"
5
 
6
+ # Load tools from your MCP server
7
+ kb_tool = Tool.from_mcp(MCP_URL, name="search_knowledge_base")
8
+ web_tool = Tool.from_mcp(MCP_URL, name="search_web")
9
+ format_tool = Tool.from_mcp(MCP_URL, name="format_response")
10
 
11
+ # Create agent with all three tools
12
+ agent = CodeAgent(tools=[kb_tool, web_tool, format_tool])
 
 
 
 
 
 
 
 
13
 
14
+ # Run example input
15
+ query = "My WiFi keeps disconnecting randomly. What can I do?"
16
+ response = agent.run(query)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ print("Agent's Troubleshooting Response:")
19
+ print(response)