Files changed (1) hide show
  1. app.py +23 -2
app.py CHANGED
@@ -3,6 +3,9 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
 
 
 
6
  from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
@@ -17,6 +20,24 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
17
  arg2: the second argument
18
  """
19
  return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -49,13 +70,13 @@ custom_role_conversions=None,
49
 
50
  # Import tool from Hub
51
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
52
-
53
  with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(stream)
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ import qrcode
7
+ import os
8
+ import time
9
  from tools.final_answer import FinalAnswerTool
10
 
11
  from Gradio_UI import GradioUI
 
20
  arg2: the second argument
21
  """
22
  return "What magic will you build ?"
23
+ @tool
24
+ def generate_qr_code(text: str) -> str:
25
+ """Generates a QR code image encoding the given text or URL and saves it to a file.
26
+ Args:
27
+ text: The text, URL, or data to encode into the QR code.
28
+ """
29
+ try:
30
+ img = qrcode.make(text)
31
+
32
+ # Create a unique filename so multiple QR codes don't overwrite each other
33
+ filename = f"qrcode_{int(time.time())}.png"
34
+ filepath = os.path.join(os.getcwd(), filename)
35
+
36
+ img.save(filepath)
37
+
38
+ return f"QR code generated successfully and saved at: {filepath}"
39
+ except Exception as e:
40
+ return f"Error generating QR code for '{text}': {str(e)}"
41
 
42
  @tool
43
  def get_current_time_in_timezone(timezone: str) -> str:
 
70
 
71
  # Import tool from Hub
72
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
73
+ tools=[final_answer, generate_qr_code, image_generation_tool],
74
  with open("prompts.yaml", 'r') as stream:
75
  prompt_templates = yaml.safe_load(stream)
76
 
77
  agent = CodeAgent(
78
  model=model,
79
+ tools=[final_answer, generate_qr_code], # <-- added here
80
  max_steps=6,
81
  verbosity_level=1,
82
  grammar=None,