hsila commited on
Commit
e0848ba
·
1 Parent(s): fe13ef4

feat: add qr code generator

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -1,6 +1,6 @@
1
  from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
- import requests
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 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
- chars = len(text)
20
- chars_no_spaces = len(text.replace(" ", ""))
21
- sentences = len(re.split(r"[.!?]+", text)) - 1
22
- print(
23
- f"Words: {words}, Characters: {chars}, Characters (no spaces): {chars_no_spaces}, Sentences: {sentences}"
24
- )
 
 
 
 
 
 
 
 
 
25
 
26
 
27
  @tool
@@ -64,7 +73,8 @@ agent = CodeAgent(
64
  tools=[
65
  final_answer,
66
  get_current_time_in_timezone,
67
- word_count,
 
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,