joshuarauh commited on
Commit
bfe4451
·
verified ·
1 Parent(s): 209e476

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -345,26 +345,36 @@ def extract_and_run_sympy_code(response_text):
345
  sympy_code = '\n'.join(filtered_lines)
346
  logger.debug(f"Code after removing imports:\n{sympy_code}")
347
 
348
- # Create globals dict with all SymPy symbols
349
  import io
350
  import sys
351
  from contextlib import redirect_stdout
 
352
 
353
- # Import SymPy first at the function level
354
  import sympy
355
 
356
- # Create output buffer
357
- output_buffer = io.StringIO()
358
-
359
  # Create globals dict with SymPy module
360
  globals_dict = {
361
  '__builtins__': __builtins__,
 
362
  'symbols': sympy.symbols,
363
- 'diff': sympy.diff,
364
  'solve': sympy.solve,
 
365
  'integrate': sympy.integrate,
 
366
  'oo': sympy.oo,
367
- 'Sum': sympy.Sum
 
 
 
 
 
 
 
 
 
 
368
  }
369
 
370
  logger.debug(f"Globals dictionary contains: {list(globals_dict.keys())}")
@@ -387,11 +397,10 @@ def extract_and_run_sympy_code(response_text):
387
 
388
  # Add stdout if there was any
389
  if stdout_output.strip():
390
- output_lines.append(f"Output:")
391
- output_lines.append(stdout_output.strip())
392
 
393
  # Add variables
394
- output_lines.append("\nVariables:")
395
  for name, value in local_vars.items():
396
  if not name.startswith('__') and not hasattr(value, '__module__'):
397
  output_lines.append(f"{name} = {value}")
@@ -407,7 +416,7 @@ def extract_and_run_sympy_code(response_text):
407
  import traceback
408
  logger.error(f"Full traceback:\n{traceback.format_exc()}")
409
  return f"Error executing SymPy code: {str(e)}"
410
-
411
 
412
  # Create Gradio interface
413
  with gr.Blocks() as interface:
 
345
  sympy_code = '\n'.join(filtered_lines)
346
  logger.debug(f"Code after removing imports:\n{sympy_code}")
347
 
348
+ # Create output buffer
349
  import io
350
  import sys
351
  from contextlib import redirect_stdout
352
+ output_buffer = io.StringIO()
353
 
354
+ # Import SymPy
355
  import sympy
356
 
 
 
 
357
  # Create globals dict with SymPy module
358
  globals_dict = {
359
  '__builtins__': __builtins__,
360
+ 'Symbol': sympy.Symbol,
361
  'symbols': sympy.symbols,
 
362
  'solve': sympy.solve,
363
+ 'diff': sympy.diff,
364
  'integrate': sympy.integrate,
365
+ 'limit': sympy.limit,
366
  'oo': sympy.oo,
367
+ 'Sum': sympy.Sum,
368
+ 'simplify': sympy.simplify,
369
+ 'expand': sympy.expand,
370
+ 'factor': sympy.factor,
371
+ 'sin': sympy.sin,
372
+ 'cos': sympy.cos,
373
+ 'tan': sympy.tan,
374
+ 'exp': sympy.exp,
375
+ 'log': sympy.log,
376
+ 'sqrt': sympy.sqrt,
377
+ 'pi': sympy.pi
378
  }
379
 
380
  logger.debug(f"Globals dictionary contains: {list(globals_dict.keys())}")
 
397
 
398
  # Add stdout if there was any
399
  if stdout_output.strip():
400
+ output_lines.extend(["", "Output:", stdout_output.strip()])
 
401
 
402
  # Add variables
403
+ output_lines.extend(["", "Variables:"])
404
  for name, value in local_vars.items():
405
  if not name.startswith('__') and not hasattr(value, '__module__'):
406
  output_lines.append(f"{name} = {value}")
 
416
  import traceback
417
  logger.error(f"Full traceback:\n{traceback.format_exc()}")
418
  return f"Error executing SymPy code: {str(e)}"
419
+
420
 
421
  # Create Gradio interface
422
  with gr.Blocks() as interface: