Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,17 +6,34 @@ import yaml
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
| 8 |
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
|
| 13 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +72,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
+
from langdetect import detect
|
| 10 |
+
from googletrans import Translator
|
| 11 |
+
|
| 12 |
+
translator = Translator()
|
| 13 |
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
| 16 |
+
def greet_in_local_language(timezone: str) -> str:
|
| 17 |
+
"""A tool that greets the user in the local timezone's language.
|
| 18 |
+
|
| 19 |
Args:
|
| 20 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
|
|
|
| 21 |
"""
|
| 22 |
+
try:
|
| 23 |
+
# Get the current local time
|
| 24 |
+
tz = pytz.timezone(timezone)
|
| 25 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 26 |
+
|
| 27 |
+
# Detect language based on timezone location
|
| 28 |
+
lang_code = detect(timezone.split('/')[-1].replace('_', ' '))
|
| 29 |
+
|
| 30 |
+
# Translate greeting into detected language
|
| 31 |
+
greeting = "Hello! Have a great day!"
|
| 32 |
+
translated_greeting = translator.translate(greeting, dest=lang_code).text
|
| 33 |
+
|
| 34 |
+
return f"{translated_greeting} The current local time in {timezone} is: {local_time}"
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Error generating greeting for timezone '{timezone}': {str(e)}"
|
| 37 |
|
| 38 |
@tool
|
| 39 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 72 |
|
| 73 |
agent = CodeAgent(
|
| 74 |
model=model,
|
| 75 |
+
tools=[inal_answer, greet_in_local_language], ## add your tools here (don't remove final answer)
|
| 76 |
max_steps=6,
|
| 77 |
verbosity_level=1,
|
| 78 |
grammar=None,
|