Spaces:
Runtime error
Runtime error
Added QR Code generation tool
Browse filesThis tool is designed to take in textual data or URLs from the user and generate and return a QR Code.
app.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
|
|
|
|
|
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
@@ -9,14 +12,35 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def my_custom_tool(
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
+
import os
|
| 4 |
+
import qrcode
|
| 5 |
+
import base64
|
| 6 |
import requests
|
| 7 |
import pytz
|
| 8 |
import yaml
|
|
|
|
| 12 |
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 14 |
@tool
|
| 15 |
+
def my_custom_tool(text:str, size:int = 200)-> str: #it's import to specify the return type
|
| 16 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 17 |
+
"""A tool that generates a QR Code for taxt or URLs
|
| 18 |
Args:
|
| 19 |
+
text: The text or the URL to make into a QR Code
|
| 20 |
+
size: Size in pixels (200 by default)
|
| 21 |
"""
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
qr = qrcode.QRCode(version=1, box_size=size//25, border=4)
|
| 25 |
+
qr.add_data(text)
|
| 26 |
+
qr.make(fit=True)
|
| 27 |
+
|
| 28 |
+
img = qr.make_image(fill_color="black", back_color="white")
|
| 29 |
+
|
| 30 |
+
# Convert to base64 for display
|
| 31 |
+
buffer = io.BytesIO()
|
| 32 |
+
img.save(buffer, format='PNG')
|
| 33 |
+
img_str = base64.b64encode(buffer.getvalue()).decode()
|
| 34 |
+
|
| 35 |
+
# Also save file
|
| 36 |
+
filename = f"qr_code_{len(text)}chars.png"
|
| 37 |
+
img.save(filename)
|
| 38 |
+
|
| 39 |
+
return f"QR code generated for: {text[:50]}...\nSaved as: {filename}\n\n"
|
| 40 |
+
|
| 41 |
+
except Exception as e:
|
| 42 |
+
return f"Error: {str(e)}"
|
| 43 |
+
#return "What magic will you build ?"
|
| 44 |
|
| 45 |
@tool
|
| 46 |
def get_current_time_in_timezone(timezone: str) -> str:
|