Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,18 +46,15 @@ def brave_search_context(query, count=3):
|
|
| 46 |
return ""
|
| 47 |
|
| 48 |
### CALCULATOR TOOL
|
|
|
|
|
|
|
| 49 |
def evaluate_expression(expr) -> str:
|
| 50 |
"""
|
| 51 |
Evaluate a simple algebraic expression string safely.
|
| 52 |
Supports +, -, *, /, **, and parentheses.
|
| 53 |
Retries evaluation after stripping non-numeric/non-operator characters if needed.
|
| 54 |
"""
|
| 55 |
-
|
| 56 |
-
allowed_names = {
|
| 57 |
-
k: v for k, v in vars(__builtins__).items()
|
| 58 |
-
if k in ("abs", "round")
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
allowed_names.update({k: getattr(math, k) for k in ("sqrt", "pow")})
|
| 62 |
|
| 63 |
def safe_eval(expression):
|
|
|
|
| 46 |
return ""
|
| 47 |
|
| 48 |
### CALCULATOR TOOL
|
| 49 |
+
import builtins
|
| 50 |
+
|
| 51 |
def evaluate_expression(expr) -> str:
|
| 52 |
"""
|
| 53 |
Evaluate a simple algebraic expression string safely.
|
| 54 |
Supports +, -, *, /, **, and parentheses.
|
| 55 |
Retries evaluation after stripping non-numeric/non-operator characters if needed.
|
| 56 |
"""
|
| 57 |
+
allowed_names = {k: getattr(builtins, k) for k in ("abs", "round")}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
allowed_names.update({k: getattr(math, k) for k in ("sqrt", "pow")})
|
| 59 |
|
| 60 |
def safe_eval(expression):
|