Artificial-superintelligence commited on
Commit
3b4c467
·
verified ·
1 Parent(s): 7ef8775

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -3
app.py CHANGED
@@ -38,12 +38,10 @@ def execute_code():
38
  return jsonify({"result": "Error: No command provided."})
39
 
40
  try:
41
- # If the command starts with "!", treat it as a shell command
42
  if command.startswith("!"):
43
  shell_command = command[1:]
44
  return Response(stream_with_context(execute_shell_command(shell_command)))
45
  else:
46
- # Treat the command as Python code
47
  process = subprocess.run(
48
  ["python3", "-c", command],
49
  stdout=subprocess.PIPE,
@@ -60,7 +58,7 @@ def cleanup():
60
  global temp_dir
61
  if os.path.exists(temp_dir):
62
  shutil.rmtree(temp_dir)
63
- temp_dir = tempfile.mkdtemp() # Recreate for a new session
64
  return jsonify({"result": "Temporary files cleaned up."})
65
 
66
  if __name__ == "__main__":
 
38
  return jsonify({"result": "Error: No command provided."})
39
 
40
  try:
 
41
  if command.startswith("!"):
42
  shell_command = command[1:]
43
  return Response(stream_with_context(execute_shell_command(shell_command)))
44
  else:
 
45
  process = subprocess.run(
46
  ["python3", "-c", command],
47
  stdout=subprocess.PIPE,
 
58
  global temp_dir
59
  if os.path.exists(temp_dir):
60
  shutil.rmtree(temp_dir)
61
+ temp_dir = tempfile.mkdtemp()
62
  return jsonify({"result": "Temporary files cleaned up."})
63
 
64
  if __name__ == "__main__":