Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,25 +8,26 @@ from tools.final_answer import FinalAnswerTool
|
|
| 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 calculator(operation: str) -> str:
|
| 13 |
-
"""
|
| 14 |
-
|
| 15 |
-
|
| 16 |
Args:
|
| 17 |
-
operation
|
| 18 |
-
|
|
|
|
| 19 |
Returns:
|
| 20 |
-
str: The result of the calculation
|
| 21 |
-
|
| 22 |
-
Raises:
|
| 23 |
-
ValueError: If the operation is invalid or cannot be computed.
|
| 24 |
"""
|
| 25 |
try:
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
-
|
| 30 |
|
| 31 |
@tool
|
| 32 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
+
|
| 12 |
@tool
|
| 13 |
def calculator(operation: str) -> str:
|
| 14 |
+
"""A simple calculator tool that safely evaluates basic math expressions.
|
| 15 |
+
|
|
|
|
| 16 |
Args:
|
| 17 |
+
operation: The mathematical expression to evaluate (e.g., "2 + 2", "5 * 3").
|
| 18 |
+
Supports basic operations (+, -, *, /) and parentheses.
|
| 19 |
+
|
| 20 |
Returns:
|
| 21 |
+
str: The result of the calculation or an error message
|
|
|
|
|
|
|
|
|
|
| 22 |
"""
|
| 23 |
try:
|
| 24 |
+
allowed_chars = set("0123456789+-*/ .()")
|
| 25 |
+
if not all(c in allowed_chars for c in operation):
|
| 26 |
+
return "Error: Only basic math operations allowed"
|
| 27 |
+
result = eval(operation, {"__builtins__": {}})
|
| 28 |
+
return f"Result: {result}"
|
| 29 |
except Exception as e:
|
| 30 |
+
return f"Error calculating {operation}: {str(e)}"
|
| 31 |
|
| 32 |
@tool
|
| 33 |
def get_current_time_in_timezone(timezone: str) -> str:
|