hhval commited on
Commit
ff369c0
·
verified ·
1 Parent(s): 85ef857

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -18
app.py CHANGED
@@ -4,30 +4,24 @@ import requests
4
  import pytz
5
  import yaml
6
  import json
 
 
7
  from tools.final_answer import FinalAnswerTool
8
- import subprocess
9
 
10
  from Gradio_UI import GradioUI
11
 
12
- try:
13
- subprocess.run(["pip", "install", "googletrans==4.0.0-rc1"], check=True)
14
- except subprocess.CalledProcessError:
15
- print("Failed to install googletrans.")
16
-
17
- from googletrans import Translator
18
-
19
  @tool
20
- def translate_to_norwegian(text: str) -> str:
21
- """A tool that translates the input text to Norwegian using Google Translate.
22
  Args:
23
- text: The text to translate.
24
  """
25
- translator = Translator()
26
- try:
27
- translation = translator.translate(text, dest="no")
28
- return translation.text
29
- except Exception as e:
30
- return f"Error translating text: {str(e)}"
31
 
32
  @tool
33
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -65,7 +59,7 @@ with open("prompts.yaml", 'r') as stream:
65
 
66
  agent = CodeAgent(
67
  model=model,
68
- tools=[translate_to_norwegian, final_answer], ## add your tools here (don't remove final answer)
69
  max_steps=6,
70
  verbosity_level=1,
71
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  import json
7
+ import random
8
+ import string
9
  from tools.final_answer import FinalAnswerTool
 
10
 
11
  from Gradio_UI import GradioUI
12
 
 
 
 
 
 
 
 
13
  @tool
14
+ def generate_random_password(length: int = 12) -> str:
15
+ """A tool that generates a secure random password.
16
  Args:
17
+ length: The desired length of the password (default is 12).
18
  """
19
+ if length < 4:
20
+ return "Password length must be at least 4 characters."
21
+
22
+ characters = string.ascii_letters + string.digits + string.punctuation
23
+ password = ''.join(random.choice(characters) for _ in range(length))
24
+ return password
25
 
26
  @tool
27
  def get_current_time_in_timezone(timezone: str) -> str:
 
59
 
60
  agent = CodeAgent(
61
  model=model,
62
+ tools=[generate_random_password, final_answer], ## add your tools here (don't remove final answer)
63
  max_steps=6,
64
  verbosity_level=1,
65
  grammar=None,