joshuarauh commited on
Commit
9a57eea
·
verified ·
1 Parent(s): c55aa08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -347,7 +347,7 @@ def extract_and_run_sympy_code(response_text):
347
 
348
  # Create globals dict
349
  import sys
350
- module = sys.modules[__name__] # Get the current module
351
  globals_dict = {
352
  '__builtins__': __builtins__,
353
  }
@@ -369,6 +369,14 @@ def extract_and_run_sympy_code(response_text):
369
  # Execute with try/except to catch specific error
370
  try:
371
  exec(sympy_code, globals_dict, local_vars)
 
 
 
 
 
 
 
 
372
  except NameError as e:
373
  logger.error(f"NameError during execution: {str(e)}")
374
  logger.debug(f"Available names: {list(globals_dict.keys())}")
@@ -379,18 +387,6 @@ def extract_and_run_sympy_code(response_text):
379
  logger.error(f"Other error during execution: {str(e)}")
380
  return f"Error executing SymPy code: {str(e)}"
381
 
382
- logger.debug("Code executed successfully")
383
- logger.debug(f"Local variables created: {list(local_vars.keys())}")
384
-
385
- # Print results
386
- with redirect_stdout(output_buffer):
387
- print("SymPy Calculation Results:")
388
- print("-" * 25)
389
- for var_name, value in local_vars.items():
390
- if (not var_name.startswith('__') and
391
- not hasattr(value, '__module__')):
392
- print(f"{var_name}: {value}")
393
-
394
  result = output_buffer.getvalue()
395
  logger.debug(f"Final output:\n{result}")
396
  return result
@@ -401,6 +397,7 @@ def extract_and_run_sympy_code(response_text):
401
  logger.error(f"Full traceback:\n{traceback.format_exc()}")
402
  return f"Error executing SymPy code: {str(e)}"
403
 
 
404
  # Create Gradio interface
405
  with gr.Blocks() as interface:
406
  gr.Markdown("# Advanced Mathematics Question Generator")
 
347
 
348
  # Create globals dict
349
  import sys
350
+ module = sys.modules[__name__]
351
  globals_dict = {
352
  '__builtins__': __builtins__,
353
  }
 
369
  # Execute with try/except to catch specific error
370
  try:
371
  exec(sympy_code, globals_dict, local_vars)
372
+
373
+ # Print all variables that were created
374
+ print("SymPy Calculation Results:")
375
+ print("-" * 25)
376
+ for var_name, value in local_vars.items():
377
+ if (not var_name.startswith('__') and
378
+ not hasattr(value, '__module__')):
379
+ print(f"{var_name} = {value}")
380
  except NameError as e:
381
  logger.error(f"NameError during execution: {str(e)}")
382
  logger.debug(f"Available names: {list(globals_dict.keys())}")
 
387
  logger.error(f"Other error during execution: {str(e)}")
388
  return f"Error executing SymPy code: {str(e)}"
389
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  result = output_buffer.getvalue()
391
  logger.debug(f"Final output:\n{result}")
392
  return result
 
397
  logger.error(f"Full traceback:\n{traceback.format_exc()}")
398
  return f"Error executing SymPy code: {str(e)}"
399
 
400
+
401
  # Create Gradio interface
402
  with gr.Blocks() as interface:
403
  gr.Markdown("# Advanced Mathematics Question Generator")