Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ from Gradio_UI import GradioUI
|
|
| 11 |
@tool
|
| 12 |
def calculator(expression: str)-> str: # Returns a string result
|
| 13 |
"""
|
| 14 |
-
A tool able to solve mathematical expressions using the mathjs.org
|
| 15 |
|
| 16 |
Args:
|
| 17 |
expression: A mathematical expression to solve (e.g., "1+2", "3*5").
|
|
@@ -19,10 +19,11 @@ def calculator(expression: str)-> str: # Returns a string result
|
|
| 19 |
Returns:
|
| 20 |
str: The result of the calculation if successful, or an error message if the request fails.
|
| 21 |
"""
|
| 22 |
-
#
|
| 23 |
-
|
|
|
|
| 24 |
try:
|
| 25 |
-
api_url = f"http://api.mathjs.org/v4/?expr={
|
| 26 |
|
| 27 |
response = requests.get(api_url)
|
| 28 |
|
|
|
|
| 11 |
@tool
|
| 12 |
def calculator(expression: str)-> str: # Returns a string result
|
| 13 |
"""
|
| 14 |
+
A tool able to solve mathematical expressions using the mathjs.org API.
|
| 15 |
|
| 16 |
Args:
|
| 17 |
expression: A mathematical expression to solve (e.g., "1+2", "3*5").
|
|
|
|
| 19 |
Returns:
|
| 20 |
str: The result of the calculation if successful, or an error message if the request fails.
|
| 21 |
"""
|
| 22 |
+
# URL-encode to ensure correct API interpretation
|
| 23 |
+
encoded_expression = urllib.parse.quote(expression, safe="") # Ensures correct API encoding
|
| 24 |
+
|
| 25 |
try:
|
| 26 |
+
api_url = f"http://api.mathjs.org/v4/?expr={encoded_expression}"
|
| 27 |
|
| 28 |
response = requests.get(api_url)
|
| 29 |
|