Spaces:
Runtime error
Runtime error
feat: add qr code generator
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
| 3 |
-
import
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
@@ -10,18 +10,27 @@ from Gradio_UI import GradioUI
|
|
| 10 |
|
| 11 |
|
| 12 |
@tool
|
| 13 |
-
def
|
| 14 |
"""A tool that analyzes text and provide word, character, and sentence counts.
|
| 15 |
Args:
|
| 16 |
text: The text to analyze
|
| 17 |
"""
|
| 18 |
words = len(re.findall(r"\b\w+\b", text))
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
@tool
|
|
@@ -64,7 +73,8 @@ agent = CodeAgent(
|
|
| 64 |
tools=[
|
| 65 |
final_answer,
|
| 66 |
get_current_time_in_timezone,
|
| 67 |
-
|
|
|
|
| 68 |
DuckDuckGoSearchTool(),
|
| 69 |
],
|
| 70 |
max_steps=6,
|
|
|
|
| 1 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
| 3 |
+
import qrcode
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
@tool
|
| 13 |
+
def get_word_count(text: str) -> str:
|
| 14 |
"""A tool that analyzes text and provide word, character, and sentence counts.
|
| 15 |
Args:
|
| 16 |
text: The text to analyze
|
| 17 |
"""
|
| 18 |
words = len(re.findall(r"\b\w+\b", text))
|
| 19 |
+
return words
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@tool
|
| 23 |
+
def get_qr_code(url: str) -> str:
|
| 24 |
+
"""A tool that generates a QR code for a given URL.
|
| 25 |
+
Args:
|
| 26 |
+
url: The URL to encode in the QR code.
|
| 27 |
+
"""
|
| 28 |
+
qr = qrcode.QRCode(version=1, box_size=10, border=5)
|
| 29 |
+
qr.add_data(url)
|
| 30 |
+
qr.make(fit=True)
|
| 31 |
+
img = qr.make_image(fill_color="black", back_color="white")
|
| 32 |
+
|
| 33 |
+
return img.get_image()
|
| 34 |
|
| 35 |
|
| 36 |
@tool
|
|
|
|
| 73 |
tools=[
|
| 74 |
final_answer,
|
| 75 |
get_current_time_in_timezone,
|
| 76 |
+
get_word_count,
|
| 77 |
+
get_qr_code,
|
| 78 |
DuckDuckGoSearchTool(),
|
| 79 |
],
|
| 80 |
max_steps=6,
|