Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,33 +9,37 @@ from Gradio_UI import GradioUI
|
|
| 9 |
# --- FERRAMENTAS PERSONALIZADAS ---
|
| 10 |
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
"""Calcula a diferença de horas entre
|
| 14 |
Args:
|
| 15 |
-
|
|
|
|
| 16 |
"""
|
| 17 |
try:
|
| 18 |
# Definir as timezones
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
-
# Obter a data atual
|
| 23 |
now = datetime.datetime.now()
|
| 24 |
|
| 25 |
-
# Calcular
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
-
diff =
|
| 30 |
|
| 31 |
if diff == 0:
|
| 32 |
-
return f"Não há diferença horária entre {
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
except Exception as e:
|
| 38 |
-
return f"Erro ao calcular a diferença: {str(e)}"
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -77,7 +81,7 @@ agent = CodeAgent(
|
|
| 77 |
tools=[
|
| 78 |
final_answer,
|
| 79 |
search_tool,
|
| 80 |
-
|
| 81 |
get_current_time_in_timezone
|
| 82 |
],
|
| 83 |
max_steps=10,
|
|
|
|
| 9 |
# --- FERRAMENTAS PERSONALIZADAS ---
|
| 10 |
|
| 11 |
@tool
|
| 12 |
+
def get_time_diff_between_timezones(timezone_a: str, timezone_b: str) -> str:
|
| 13 |
+
"""Calcula a diferença de horas entre duas timezones quaisquer.
|
| 14 |
Args:
|
| 15 |
+
timezone_a: A primeira timezone (ex: 'Europe/Lisbon').
|
| 16 |
+
timezone_b: A segunda timezone para comparar (ex: 'Asia/Tokyo').
|
| 17 |
"""
|
| 18 |
try:
|
| 19 |
# Definir as timezones
|
| 20 |
+
tz_a = pytz.timezone(timezone_a)
|
| 21 |
+
tz_b = pytz.timezone(timezone_b)
|
| 22 |
|
| 23 |
+
# Obter a data atual
|
| 24 |
now = datetime.datetime.now()
|
| 25 |
|
| 26 |
+
# Calcular os offsets em relação ao UTC
|
| 27 |
+
offset_a = tz_a.localize(now).utcoffset().total_seconds() / 3600
|
| 28 |
+
offset_b = tz_b.localize(now).utcoffset().total_seconds() / 3600
|
| 29 |
|
| 30 |
+
diff = offset_a - offset_b
|
| 31 |
|
| 32 |
if diff == 0:
|
| 33 |
+
return f"Não há diferença horária entre {timezone_a} e {timezone_b}."
|
| 34 |
|
| 35 |
+
# Lógica para explicar a diferença de forma humana
|
| 36 |
+
if diff > 0:
|
| 37 |
+
return f"{timezone_a} está {abs(diff)} horas à frente de {timezone_b}."
|
| 38 |
+
else:
|
| 39 |
+
return f"{timezone_a} está {abs(diff)} horas atrás de {timezone_b}."
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
+
return f"Erro ao calcular a diferença entre {timezone_a} e {timezone_b}: {str(e)}"
|
| 43 |
|
| 44 |
@tool
|
| 45 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 81 |
tools=[
|
| 82 |
final_answer,
|
| 83 |
search_tool,
|
| 84 |
+
get_time_diff_between_timezones, # Substitui a antiga por esta
|
| 85 |
get_current_time_in_timezone
|
| 86 |
],
|
| 87 |
max_steps=10,
|