Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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)->
|
| 12 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 13 |
-
"""A tool that
|
| 14 |
Args:
|
| 15 |
text: The text or URL that needs to be encoded into the QR code.
|
| 16 |
"""
|
| 17 |
-
|
| 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 |
-
|
| 28 |
return AgentImage(save_path)
|
| 29 |
except Exception as e:
|
| 30 |
-
return f"
|
| 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
|