Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,20 +4,19 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
|
| 11 |
@tool
|
| 12 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 13 |
"""
|
| 14 |
-
|
| 15 |
|
| 16 |
Args:
|
| 17 |
-
timezone
|
| 18 |
|
| 19 |
Returns:
|
| 20 |
-
|
| 21 |
"""
|
| 22 |
try:
|
| 23 |
tz = pytz.timezone(timezone)
|
|
@@ -29,14 +28,14 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 29 |
@tool
|
| 30 |
def calculator_tool(expression: str) -> str:
|
| 31 |
"""
|
| 32 |
-
|
| 33 |
|
| 34 |
Args:
|
| 35 |
-
expression
|
| 36 |
-
|
| 37 |
|
| 38 |
Returns:
|
| 39 |
-
|
| 40 |
"""
|
| 41 |
try:
|
| 42 |
# Evaluate the expression in a restricted environment for safety.
|
|
@@ -52,11 +51,11 @@ final_answer = FinalAnswerTool()
|
|
| 52 |
model = HfApiModel(
|
| 53 |
max_tokens=2096,
|
| 54 |
temperature=0.5,
|
| 55 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 56 |
custom_role_conversions=None,
|
| 57 |
)
|
| 58 |
|
| 59 |
-
# Import tool from Hub
|
| 60 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 61 |
|
| 62 |
with open("prompts.yaml", 'r') as stream:
|
|
@@ -64,7 +63,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 64 |
|
| 65 |
agent = CodeAgent(
|
| 66 |
model=model,
|
| 67 |
-
tools=[final_answer, calculator_tool], # Added our calculator tool
|
| 68 |
max_steps=6,
|
| 69 |
verbosity_level=1,
|
| 70 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
from Gradio_UI import GradioUI
|
| 8 |
|
| 9 |
|
| 10 |
@tool
|
| 11 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 12 |
"""
|
| 13 |
+
Fetches the current local time for the specified timezone.
|
| 14 |
|
| 15 |
Args:
|
| 16 |
+
timezone: A valid timezone string.
|
| 17 |
|
| 18 |
Returns:
|
| 19 |
+
A string message with the current local time, or an error message.
|
| 20 |
"""
|
| 21 |
try:
|
| 22 |
tz = pytz.timezone(timezone)
|
|
|
|
| 28 |
@tool
|
| 29 |
def calculator_tool(expression: str) -> str:
|
| 30 |
"""
|
| 31 |
+
Evaluates a mathematical expression.
|
| 32 |
|
| 33 |
Args:
|
| 34 |
+
expression: A string representing a mathematical expression.
|
| 35 |
+
Supported operators: +, -, *, /, **, and %.
|
| 36 |
|
| 37 |
Returns:
|
| 38 |
+
A string representing the result of the calculation, or an error message if evaluation fails.
|
| 39 |
"""
|
| 40 |
try:
|
| 41 |
# Evaluate the expression in a restricted environment for safety.
|
|
|
|
| 51 |
model = HfApiModel(
|
| 52 |
max_tokens=2096,
|
| 53 |
temperature=0.5,
|
| 54 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 55 |
custom_role_conversions=None,
|
| 56 |
)
|
| 57 |
|
| 58 |
+
# Import tool from Hub (e.g., text-to-image)
|
| 59 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 60 |
|
| 61 |
with open("prompts.yaml", 'r') as stream:
|
|
|
|
| 63 |
|
| 64 |
agent = CodeAgent(
|
| 65 |
model=model,
|
| 66 |
+
tools=[final_answer, calculator_tool], # Added final_answer and our calculator tool
|
| 67 |
max_steps=6,
|
| 68 |
verbosity_level=1,
|
| 69 |
grammar=None,
|