yasserrmd commited on
Commit
e779fad
·
verified ·
1 Parent(s): 754a3e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -49,7 +49,9 @@ if st.button("Generate Diagram"):
49
  with open(temp_file, "w") as f:
50
  f.write(python_code)
51
 
52
- # Execute the code and look for 'diagram.jpg'
 
 
53
  try:
54
  exec(open(temp_file).read())
55
  diagram_path = os.path.join(tmpdirname, "diagram.jpg")
@@ -61,6 +63,8 @@ if st.button("Generate Diagram"):
61
  st.error("No diagram image was generated.")
62
  except Exception as e:
63
  st.error(f"Error executing the Python code: {e}")
 
 
64
  else:
65
  st.write("Response:", output)
66
  else:
 
49
  with open(temp_file, "w") as f:
50
  f.write(python_code)
51
 
52
+ # Change directory to temp and execute the code
53
+ original_dir = os.getcwd()
54
+ os.chdir(tmpdirname)
55
  try:
56
  exec(open(temp_file).read())
57
  diagram_path = os.path.join(tmpdirname, "diagram.jpg")
 
63
  st.error("No diagram image was generated.")
64
  except Exception as e:
65
  st.error(f"Error executing the Python code: {e}")
66
+ finally:
67
+ os.chdir(original_dir) # Restore the original directory
68
  else:
69
  st.write("Response:", output)
70
  else: