Spaces:
Runtime error
Runtime error
| from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool | |
| from PIL import Image | |
| import datetime | |
| import os | |
| import io | |
| import qrcode | |
| import base64 | |
| import requests | |
| import pytz | |
| import yaml | |
| from tools.final_answer import FinalAnswerTool | |
| from Gradio_UI import GradioUI | |
| def image_path_to_markdown(path: str) -> str: | |
| try: | |
| with open(path, "rb") as f: | |
| img_bytes = f.read() | |
| img_base64 = base64.b64encode(img_bytes).decode("utf-8") | |
| return f"" | |
| except Exception as e: | |
| return f"Image saved at: {path} (Failed to embed image: {str(e)})" | |
| def greeting_tool(greeting: str) -> str: | |
| """A tool to respond to user greetings and start a conversation. | |
| Args: | |
| greeting: The greeting message from the user (e.g., 'Hello', 'Hi') | |
| """ | |
| responses = [ | |
| "Hello! I'm your Tech Troubleshooting Assistant. How can I help you today?", | |
| "Hi there! What tech issue are you experiencing?", | |
| "Greetings! I'm here to help with your technical problems. What's troubling you?", | |
| "Hello! Ready to solve some tech problems? What's the issue?" | |
| ] | |
| import random | |
| return random.choice(responses) | |
| def basic_troubleshooting(problem: str) -> str: | |
| """Provides basic troubleshooting steps for common tech issues. | |
| Args: | |
| problem: Description of the technical problem | |
| """ | |
| common_solutions = { | |
| "internet": "1. Restart your router\n2. Check cable connections\n3. Restart your device\n4. Contact your ISP if problem persists", | |
| "printer": "1. Check power and connections\n2. Restart printer\n3. Reinstall drivers\n4. Check for paper jams", | |
| "slow computer": "1. Close unused programs\n2. Run disk cleanup\n3. Check for malware\n4. Add more RAM if needed", | |
| "email": "1. Check internet connection\n2. Verify login credentials\n3. Check server status\n4. Try webmail version" | |
| } | |
| problem_lower = problem.lower() | |
| for key in common_solutions: | |
| if key in problem_lower: | |
| return f"For {problem}:\n\n{common_solutions[key]}" | |
| 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" | |
| def check_service_status(service: str) -> str: | |
| """Checks the status of popular online services. | |
| Args: | |
| service: Name of the service to check (e.g., 'Gmail', 'AWS') | |
| """ | |
| status_pages = { | |
| "gmail": "https://www.google.com/appsstatus", | |
| "aws": "https://health.aws.amazon.com/", | |
| "microsoft": "https://portal.office.com/servicestatus", | |
| "slack": "https://status.slack.com/", | |
| "zoom": "https://status.zoom.us/" | |
| } | |
| service_lower = service.lower() | |
| if service_lower in status_pages: | |
| return f"You can check {service}'s status here: {status_pages[service_lower]}" | |
| return f"I don't have a direct link for {service}'s status page. Try searching 'Is {service} down?' on a search engine." | |
| def software_update_check(os_type: str) -> str: | |
| """Provides instructions for checking software updates on different operating systems. | |
| Args: | |
| os_type: The operating system (Windows, Mac, Linux, Android, iOS) | |
| """ | |
| instructions = { | |
| "windows": "1. Open Settings\n2. Go to Update & Security\n3. Click Check for updates", | |
| "mac": "1. Click Apple menu\n2. Select System Preferences\n3. Click Software Update", | |
| "linux": "For Ubuntu: Run 'sudo apt update && sudo apt upgrade' in terminal", | |
| "android": "1. Open Settings\n2. Tap System\n3. Tap Advanced\n4. Tap System update", | |
| "ios": "1. Open Settings\n2. Tap General\n3. Tap Software Update" | |
| } | |
| os_lower = os_type.lower() | |
| if os_lower in instructions: | |
| return f"To check for updates on {os_type}:\n\n{instructions[os_lower]}" | |
| return f"I don't have specific instructions for {os_type}. Try searching online for 'how to check updates on {os_type}'." | |
| final_answer = FinalAnswerTool() | |
| model = HfApiModel( | |
| max_tokens=2096, | |
| temperature=0.5, | |
| model_id='Qwen/Qwen2.5-Coder-32B-Instruct', | |
| custom_role_conversions=None, | |
| ) | |
| search_tool = DuckDuckGoSearchTool() | |
| with open("prompts.yaml", 'r') as stream: | |
| prompt_templates = yaml.safe_load(stream) | |
| agent = CodeAgent( | |
| model=model, | |
| tools=[final_answer, greeting_tool, basic_troubleshooting, check_service_status, software_update_check, search_tool], | |
| max_steps=6, | |
| verbosity_level=1, | |
| grammar=None, | |
| planning_interval=None, | |
| name=None, | |
| description=None, | |
| prompt_templates=prompt_templates | |
| ) | |
| GradioUI(agent).launch() |