Update app.py
Browse files
app.py
CHANGED
@@ -22,96 +22,87 @@ def image_path_to_markdown(path: str) -> str:
|
|
22 |
return f"Image saved at: {path} (Failed to embed image: {str(e)})"
|
23 |
|
24 |
|
25 |
-
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
26 |
@tool
|
27 |
-
def
|
28 |
-
|
29 |
-
"""A tool that generates a QR Code for taxt or URLs
|
30 |
Args:
|
31 |
-
|
32 |
-
size: Size in pixels (200 by default)
|
33 |
"""
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
# Convert to base64 for display
|
43 |
-
buffer = io.BytesIO()
|
44 |
-
img.save(buffer, format='PNG')
|
45 |
-
img_str = base64.b64encode(buffer.getvalue()).decode()
|
46 |
-
|
47 |
-
# Also save file
|
48 |
-
filename = f"qr_code_{len(text)}chars.png"
|
49 |
-
img.save(filename)
|
50 |
-
|
51 |
-
return f"QR code generated for: {text[:50]}...\nSaved as: {filename}\n\n"
|
52 |
-
|
53 |
-
except Exception as e:
|
54 |
-
return f"Error: {str(e)}"
|
55 |
-
#return "What magic will you build ?"
|
56 |
|
57 |
@tool
|
58 |
-
def
|
59 |
-
"""
|
60 |
Args:
|
61 |
-
|
62 |
"""
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
77 |
-
|
78 |
-
model = HfApiModel(
|
79 |
-
max_tokens=2096,
|
80 |
-
temperature=0.5,
|
81 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
82 |
-
custom_role_conversions=None,
|
83 |
-
)
|
84 |
-
|
85 |
-
|
86 |
-
# Import tool from Hub
|
87 |
-
original_image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
88 |
|
89 |
@tool
|
90 |
-
def
|
91 |
-
"""
|
92 |
-
|
93 |
Args:
|
94 |
-
|
95 |
"""
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
return f"Image generated for prompt: '{prompt}'\nSaved as: {filename}\n\n"
|
110 |
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
|
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
search_tool = DuckDuckGoSearchTool()
|
117 |
|
@@ -120,7 +111,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
120 |
|
121 |
agent = CodeAgent(
|
122 |
model=model,
|
123 |
-
tools=[final_answer,
|
124 |
max_steps=6,
|
125 |
verbosity_level=1,
|
126 |
grammar=None,
|
@@ -130,5 +121,4 @@ agent = CodeAgent(
|
|
130 |
prompt_templates=prompt_templates
|
131 |
)
|
132 |
|
133 |
-
|
134 |
GradioUI(agent).launch()
|
|
|
22 |
return f"Image saved at: {path} (Failed to embed image: {str(e)})"
|
23 |
|
24 |
|
|
|
25 |
@tool
|
26 |
+
def greeting_tool(greeting: str) -> str:
|
27 |
+
"""A tool to respond to user greetings and start a conversation.
|
|
|
28 |
Args:
|
29 |
+
greeting: The greeting message from the user (e.g., 'Hello', 'Hi')
|
|
|
30 |
"""
|
31 |
+
responses = [
|
32 |
+
"Hello! I'm your Tech Troubleshooting Assistant. How can I help you today?",
|
33 |
+
"Hi there! What tech issue are you experiencing?",
|
34 |
+
"Greetings! I'm here to help with your technical problems. What's troubling you?",
|
35 |
+
"Hello! Ready to solve some tech problems? What's the issue?"
|
36 |
+
]
|
37 |
+
import random
|
38 |
+
return random.choice(responses)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
@tool
|
41 |
+
def basic_troubleshooting(problem: str) -> str:
|
42 |
+
"""Provides basic troubleshooting steps for common tech issues.
|
43 |
Args:
|
44 |
+
problem: Description of the technical problem
|
45 |
"""
|
46 |
+
common_solutions = {
|
47 |
+
"internet": "1. Restart your router\n2. Check cable connections\n3. Restart your device\n4. Contact your ISP if problem persists",
|
48 |
+
"printer": "1. Check power and connections\n2. Restart printer\n3. Reinstall drivers\n4. Check for paper jams",
|
49 |
+
"slow computer": "1. Close unused programs\n2. Run disk cleanup\n3. Check for malware\n4. Add more RAM if needed",
|
50 |
+
"email": "1. Check internet connection\n2. Verify login credentials\n3. Check server status\n4. Try webmail version"
|
51 |
+
}
|
52 |
+
|
53 |
+
problem_lower = problem.lower()
|
54 |
+
for key in common_solutions:
|
55 |
+
if key in problem_lower:
|
56 |
+
return f"For {problem}:\n\n{common_solutions[key]}"
|
57 |
+
|
58 |
+
return f"For {problem}, try these general steps:\n1. Restart the device\n2. Check for updates\n3. Verify connections\n4. Search online for specific solutions"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
@tool
|
61 |
+
def check_service_status(service: str) -> str:
|
62 |
+
"""Checks the status of popular online services.
|
|
|
63 |
Args:
|
64 |
+
service: Name of the service to check (e.g., 'Gmail', 'AWS')
|
65 |
"""
|
66 |
+
status_pages = {
|
67 |
+
"gmail": "https://www.google.com/appsstatus",
|
68 |
+
"aws": "https://health.aws.amazon.com/",
|
69 |
+
"microsoft": "https://portal.office.com/servicestatus",
|
70 |
+
"slack": "https://status.slack.com/",
|
71 |
+
"zoom": "https://status.zoom.us/"
|
72 |
+
}
|
73 |
+
|
74 |
+
service_lower = service.lower()
|
75 |
+
if service_lower in status_pages:
|
76 |
+
return f"You can check {service}'s status here: {status_pages[service_lower]}"
|
77 |
+
return f"I don't have a direct link for {service}'s status page. Try searching 'Is {service} down?' on a search engine."
|
|
|
|
|
78 |
|
79 |
+
@tool
|
80 |
+
def software_update_check(os_type: str) -> str:
|
81 |
+
"""Provides instructions for checking software updates on different operating systems.
|
82 |
+
Args:
|
83 |
+
os_type: The operating system (Windows, Mac, Linux, Android, iOS)
|
84 |
+
"""
|
85 |
+
instructions = {
|
86 |
+
"windows": "1. Open Settings\n2. Go to Update & Security\n3. Click Check for updates",
|
87 |
+
"mac": "1. Click Apple menu\n2. Select System Preferences\n3. Click Software Update",
|
88 |
+
"linux": "For Ubuntu: Run 'sudo apt update && sudo apt upgrade' in terminal",
|
89 |
+
"android": "1. Open Settings\n2. Tap System\n3. Tap Advanced\n4. Tap System update",
|
90 |
+
"ios": "1. Open Settings\n2. Tap General\n3. Tap Software Update"
|
91 |
+
}
|
92 |
+
|
93 |
+
os_lower = os_type.lower()
|
94 |
+
if os_lower in instructions:
|
95 |
+
return f"To check for updates on {os_type}:\n\n{instructions[os_lower]}"
|
96 |
+
return f"I don't have specific instructions for {os_type}. Try searching online for 'how to check updates on {os_type}'."
|
97 |
|
98 |
+
final_answer = FinalAnswerTool()
|
99 |
|
100 |
+
model = HfApiModel(
|
101 |
+
max_tokens=2096,
|
102 |
+
temperature=0.5,
|
103 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
104 |
+
custom_role_conversions=None,
|
105 |
+
)
|
106 |
|
107 |
search_tool = DuckDuckGoSearchTool()
|
108 |
|
|
|
111 |
|
112 |
agent = CodeAgent(
|
113 |
model=model,
|
114 |
+
tools=[final_answer, greeting_tool, basic_troubleshooting, check_service_status, software_update_check, search_tool],
|
115 |
max_steps=6,
|
116 |
verbosity_level=1,
|
117 |
grammar=None,
|
|
|
121 |
prompt_templates=prompt_templates
|
122 |
)
|
123 |
|
|
|
124 |
GradioUI(agent).launch()
|