Spaces:
Running
Running
Update app.py
Browse files
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 |
-
#
|
|
|
|
|
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:
|