Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,20 +9,24 @@ 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(
|
| 13 |
"""
|
| 14 |
-
|
| 15 |
|
| 16 |
Args:
|
| 17 |
-
|
| 18 |
-
arg2 (int): The second operand.
|
| 19 |
|
| 20 |
Returns:
|
| 21 |
-
|
| 22 |
-
"""
|
| 23 |
-
return arg1 + arg2
|
| 24 |
-
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
@tool
|
| 28 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 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 |
+
A simple calculator that evaluates a basic arithmetic operation given as a string.
|
| 15 |
|
| 16 |
Args:
|
| 17 |
+
operation (str): A mathematical expression (e.g., '5 + 3', '10 - 2', '4 * 7', '20 / 5').
|
|
|
|
| 18 |
|
| 19 |
Returns:
|
| 20 |
+
str: The result of the calculation as a string.
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
Raises:
|
| 23 |
+
ValueError: If the operation is invalid or cannot be computed.
|
| 24 |
+
"""
|
| 25 |
+
try:
|
| 26 |
+
result = eval(operation)
|
| 27 |
+
return str(result)
|
| 28 |
+
except Exception as e:
|
| 29 |
+
raise ValueError(f"Invalid operation: {operation}. Error: {str(e)}")
|
| 30 |
|
| 31 |
@tool
|
| 32 |
def get_current_time_in_timezone(timezone: str) -> str:
|