Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -345,9 +345,10 @@ def extract_and_run_sympy_code(response_text):
|
|
345 |
# Create string buffer for output
|
346 |
output_buffer = io.StringIO()
|
347 |
|
348 |
-
# Create globals dict with all SymPy symbols
|
349 |
-
sympy_globals = {}
|
350 |
sympy_globals.update({name: getattr(sympy, name) for name in dir(sympy)})
|
|
|
351 |
|
352 |
# Create locals dict to capture new variables
|
353 |
local_vars = {}
|
@@ -360,7 +361,9 @@ def extract_and_run_sympy_code(response_text):
|
|
360 |
print("SymPy Calculation Results:")
|
361 |
print("-" * 25)
|
362 |
for var_name, value in local_vars.items():
|
363 |
-
if not var_name.startswith('__') and
|
|
|
|
|
364 |
print(f"{var_name}: {value}")
|
365 |
|
366 |
return output_buffer.getvalue()
|
|
|
345 |
# Create string buffer for output
|
346 |
output_buffer = io.StringIO()
|
347 |
|
348 |
+
# Create globals dict with all SymPy symbols and add sympy module itself
|
349 |
+
sympy_globals = {'sympy': sympy} # Add sympy module itself
|
350 |
sympy_globals.update({name: getattr(sympy, name) for name in dir(sympy)})
|
351 |
+
sympy_globals['__builtins__'] = __builtins__ # Add built-ins
|
352 |
|
353 |
# Create locals dict to capture new variables
|
354 |
local_vars = {}
|
|
|
361 |
print("SymPy Calculation Results:")
|
362 |
print("-" * 25)
|
363 |
for var_name, value in local_vars.items():
|
364 |
+
if (not var_name.startswith('__') and
|
365 |
+
not hasattr(value, '__module__') and
|
366 |
+
var_name != 'sympy'): # Don't print the sympy module itself
|
367 |
print(f"{var_name}: {value}")
|
368 |
|
369 |
return output_buffer.getvalue()
|