joshuarauh commited on
Commit
00ab419
·
verified ·
1 Parent(s): b534e76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -333,6 +333,19 @@ def extract_and_run_sympy_code(response_text):
333
  return "Malformed SymPy code block."
334
 
335
  sympy_code = response_text[code_start:code_end].strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
336
 
337
  # Import necessary modules
338
  import io
@@ -354,6 +367,7 @@ def extract_and_run_sympy_code(response_text):
354
  "exp": sympy.exp,
355
  "simplify": sympy.simplify,
356
  "expand": sympy.expand,
 
357
  "print": print, # Allow print statements
358
  "pi": sympy.pi,
359
  "N": sympy.N,
 
333
  return "Malformed SymPy code block."
334
 
335
  sympy_code = response_text[code_start:code_end].strip()
336
+
337
+ if "print" not in sympy_code and any(x in sympy_code for x in ['diff', 'integrate', 'solve']):
338
+ lines = sympy_code.split('\n')
339
+ modified_lines = []
340
+ for line in lines:
341
+ modified_lines.append(line)
342
+ # If line assigns a value and looks like it creates an expression
343
+ if ('=' in line and '#' not in line and 'import' not in line
344
+ and any(x in line for x in ['diff', 'integrate', 'solve', 'sqrt', 'log'])):
345
+ var_name = line.split('=')[0].strip()
346
+ modified_lines.append(f"print('{var_name} = ')")
347
+ modified_lines.append(f"print(simplify({var_name}))")
348
+ sympy_code = '\n'.join(modified_lines)
349
 
350
  # Import necessary modules
351
  import io
 
367
  "exp": sympy.exp,
368
  "simplify": sympy.simplify,
369
  "expand": sympy.expand,
370
+ "log": sympy.log,
371
  "print": print, # Allow print statements
372
  "pi": sympy.pi,
373
  "N": sympy.N,