Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import requests
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
@@ -19,7 +20,54 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
19 |
return "What magic will you build ?"
|
20 |
|
21 |
@tool
|
22 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
"""A tool that fetches the current local time in a specified timezone.
|
24 |
Args:
|
25 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
@@ -28,7 +76,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
28 |
# Create timezone object
|
29 |
tz = pytz.timezone(timezone)
|
30 |
# Get current time in that timezone
|
31 |
-
local_time = datetime.datetime.now(tz).strftime(
|
32 |
return f"The current local time in {timezone} is: {local_time}"
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
@@ -36,6 +84,8 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
36 |
|
37 |
final_answer = FinalAnswerTool()
|
38 |
|
|
|
|
|
39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
41 |
|
@@ -55,7 +105,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
from tools.JavaScriptToPythonConverter import JavaScriptMethodDispatcher
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
|
|
20 |
return "What magic will you build ?"
|
21 |
|
22 |
@tool
|
23 |
+
def get_datetime_format(country_code: str) -> str:
|
24 |
+
"""
|
25 |
+
Get the datetime format string for a specific country.
|
26 |
+
|
27 |
+
Args:
|
28 |
+
country_code (str): Two-letter country code (e.g., 'US', 'FR')
|
29 |
+
|
30 |
+
Returns:
|
31 |
+
str: Format string for the specified country
|
32 |
+
"""
|
33 |
+
match country_code.upper():
|
34 |
+
# European formats
|
35 |
+
case 'FR' | 'DE' | 'AT' | 'CH':
|
36 |
+
return "%d.%m.%Y %H:%M:%S"
|
37 |
+
|
38 |
+
case 'IT' | 'ES' | 'PT':
|
39 |
+
return "%d/%m/%Y %H:%M:%S"
|
40 |
+
|
41 |
+
case 'GB' | 'IE':
|
42 |
+
return "%d/%m/%Y %I:%M:%S %p"
|
43 |
+
|
44 |
+
# North American formats
|
45 |
+
case 'US':
|
46 |
+
return "%m/%d/%Y %I:%M:%S %p"
|
47 |
+
|
48 |
+
case 'CA':
|
49 |
+
return "%Y-%m-%d %H:%M:%S"
|
50 |
+
|
51 |
+
# Asian formats
|
52 |
+
case 'JP' | 'CN':
|
53 |
+
return "%Y年%m月%d日 %H:%M:%S"
|
54 |
+
|
55 |
+
case 'KR':
|
56 |
+
return "%Y년%m월%d일 %H:%M:%S"
|
57 |
+
|
58 |
+
case 'IN':
|
59 |
+
return "%d-%m-%Y %I:%M:%S %p"
|
60 |
+
|
61 |
+
# Scandinavian formats
|
62 |
+
case 'SE' | 'NO' | 'DK' | 'FI':
|
63 |
+
return "%Y-%m-%d %H:%M:%S"
|
64 |
+
|
65 |
+
# Default ISO format
|
66 |
+
case _:
|
67 |
+
return "%Y-%m-%d %H:%M:%S"
|
68 |
+
|
69 |
+
@tool
|
70 |
+
def get_current_time_in_timezone(timezone: str, timeformat: str) -> str:
|
71 |
"""A tool that fetches the current local time in a specified timezone.
|
72 |
Args:
|
73 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
|
|
76 |
# Create timezone object
|
77 |
tz = pytz.timezone(timezone)
|
78 |
# Get current time in that timezone
|
79 |
+
local_time = datetime.datetime.now(tz).strftime(timeformat)
|
80 |
return f"The current local time in {timezone} is: {local_time}"
|
81 |
except Exception as e:
|
82 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
|
|
84 |
|
85 |
final_answer = FinalAnswerTool()
|
86 |
|
87 |
+
jsCallable = JavaScriptMethodDispatcher()
|
88 |
+
|
89 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
90 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
91 |
|
|
|
105 |
|
106 |
agent = CodeAgent(
|
107 |
model=model,
|
108 |
+
tools=[final_answer, jsCallable], ## add your tools here (don't remove final answer)
|
109 |
max_steps=6,
|
110 |
verbosity_level=1,
|
111 |
grammar=None,
|