Dalageo commited on
Commit
d04fa28
·
verified ·
1 Parent(s): 6c9727f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
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
- # Remove spaces
23
- expression = expression.replace(" ","")
 
24
  try:
25
- api_url = f"http://api.mathjs.org/v4/?expr={expression}"
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