danieldeng commited on
Commit
08cbc29
·
verified ·
1 Parent(s): 1e0d6fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -6,28 +6,30 @@ import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  from Gradio_UI import GradioUI
8
 
 
 
 
9
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
10
  @tool
11
- def generate_qr_code(text:str)-> str: #it's import to specify the return type
12
  #Keep this format for the description / args / args description but feel free to modify the tool
13
- """A tool that generate a QR code image based on the input string.
14
  Args:
15
  text: The text or URL that needs to be encoded into the QR code.
16
  """
17
- import qrcode
18
  try:
19
  qr = qrcode.QRCode(box_size=10, border=4)
20
  qr.add_data(text)
21
  qr.make(fit=True)
22
-
23
  img = qr.make_image(fill_color="black", back_color="white").convert('RGB')
24
 
25
  save_path = "generated_qr.png"
26
  img.save(save_path)
27
- from smolagents.agent_types import AgentImage
28
  return AgentImage(save_path)
29
  except Exception as e:
30
- return f"QR code generation failed: {str(e)}"
31
  # return "What magic will you build ?"
32
 
33
  @tool
 
6
  from tools.final_answer import FinalAnswerTool
7
  from Gradio_UI import GradioUI
8
 
9
+ import qrcode
10
+ from smolagents.agent_types import AgentImage
11
+
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
+ def generate_qr_code(text:str)-> AgentImage: #it's import to specify the return type
15
  #Keep this format for the description / args / args description but feel free to modify the tool
16
+ """A tool that generates a QR code image and returns it.
17
  Args:
18
  text: The text or URL that needs to be encoded into the QR code.
19
  """
20
+
21
  try:
22
  qr = qrcode.QRCode(box_size=10, border=4)
23
  qr.add_data(text)
24
  qr.make(fit=True)
 
25
  img = qr.make_image(fill_color="black", back_color="white").convert('RGB')
26
 
27
  save_path = "generated_qr.png"
28
  img.save(save_path)
29
+
30
  return AgentImage(save_path)
31
  except Exception as e:
32
+ return f"Error generating QR code:{str(e)}"
33
  # return "What magic will you build ?"
34
 
35
  @tool