Manavraj commited on
Commit
4a5a8b3
·
verified ·
1 Parent(s): c74400f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -78
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 my_custom_tool(text:str, size:int = 200)-> str: #it's import to specify the return type
28
- #Keep this format for the description / args / args description but feel free to modify the tool
29
- """A tool that generates a QR Code for taxt or URLs
30
  Args:
31
- text: The text or the URL to make into a QR Code
32
- size: Size in pixels (200 by default)
33
  """
34
-
35
- try:
36
- qr = qrcode.QRCode(version=1, box_size=size//25, border=4)
37
- qr.add_data(text)
38
- qr.make(fit=True)
39
-
40
- img = qr.make_image(fill_color="black", back_color="white")
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![QR Code](data:image/png;base64,{img_str})"
52
-
53
- except Exception as e:
54
- return f"Error: {str(e)}"
55
- #return "What magic will you build ?"
56
 
57
  @tool
58
- def get_current_time_in_timezone(timezone: str) -> str:
59
- """A tool that fetches the current local time in a specified timezone.
60
  Args:
61
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
62
  """
63
- try:
64
- # Create timezone object
65
- tz = pytz.timezone(timezone)
66
- # Get current time in that timezone
67
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
68
- return f"The current local time in {timezone} is: {local_time}"
69
- except Exception as e:
70
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
71
-
72
-
73
- final_answer = FinalAnswerTool()
74
-
75
- # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
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 image_generation_tool(prompt: str) -> str:
91
- """Generates an image from a prompt and embeds it as base64 in markdown.
92
-
93
  Args:
94
- prompt: The text prompt to generate an image from.
95
  """
96
- try:
97
- # Run the tool and get back a PIL Image object
98
- image = original_image_generation_tool(prompt)
99
-
100
- # Save the image to a file
101
- filename = f"generated_image_{abs(hash(prompt))}.png"
102
- image.save(filename)
103
-
104
- # Convert image to base64 for embedding
105
- with open(filename, "rb") as f:
106
- img_bytes = f.read()
107
- img_base64 = base64.b64encode(img_bytes).decode("utf-8")
108
-
109
- return f"Image generated for prompt: '{prompt}'\nSaved as: {filename}\n\n![Generated Image](data:image/png;base64,{img_base64})"
110
 
111
- except Exception as e:
112
- return f"Error generating image: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, my_custom_tool, get_current_time_in_timezone, image_generation_tool, search_tool], ## add your tools here (don't remove 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()