hhval commited on
Commit
1bfcd25
·
verified ·
1 Parent(s): a17efc0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -4,21 +4,23 @@ import requests
4
  import pytz
5
  import yaml
6
  import json
 
7
  from tools.final_answer import FinalAnswerTool
8
 
9
  from Gradio_UI import GradioUI
10
 
11
  @tool
12
- def get_random_joke() -> str:
13
- """A tool that fetches a random joke."""
14
- url = "https://official-joke-api.appspot.com/random_joke"
15
-
 
 
16
  try:
17
- response = requests.get(url).json()
18
- joke = f"{response['setup']} {response['punchline']}"
19
- return joke
20
  except Exception as e:
21
- return f"Error fetching joke: {str(e)}"
22
 
23
  @tool
24
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -56,7 +58,7 @@ with open("prompts.yaml", 'r') as stream:
56
 
57
  agent = CodeAgent(
58
  model=model,
59
- tools=[get_random_joke, final_answer], ## add your tools here (don't remove final answer)
60
  max_steps=6,
61
  verbosity_level=1,
62
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  import json
7
+ from googletrans import Translator
8
  from tools.final_answer import FinalAnswerTool
9
 
10
  from Gradio_UI import GradioUI
11
 
12
  @tool
13
+ def translate_to_norwegian(text: str) -> str:
14
+ """A tool that translates the input text to Norwegian using Google Translate.
15
+ Args:
16
+ text: The text to translate.
17
+ """
18
+ translator = Translator()
19
  try:
20
+ translation = translator.translate(text, dest="no")
21
+ return translation.text
 
22
  except Exception as e:
23
+ return f"Error translating text: {str(e)}"
24
 
25
  @tool
26
  def get_current_time_in_timezone(timezone: str) -> str:
 
58
 
59
  agent = CodeAgent(
60
  model=model,
61
+ tools=[translate_to_norwegian, final_answer], ## add your tools here (don't remove final answer)
62
  max_steps=6,
63
  verbosity_level=1,
64
  grammar=None,