Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ def index():
|
|
27 |
if not prompt:
|
28 |
return render_template("index.html")
|
29 |
|
30 |
-
max_retries =
|
31 |
attempt = 0
|
32 |
last_error = None
|
33 |
while attempt < max_retries:
|
@@ -42,6 +42,7 @@ Plan out in chain of thought what you are going to do first, then give the final
|
|
42 |
Make sure to not use external images or resources other than default Manim, however you can use numpy or other default libraries.
|
43 |
Keep the scene uncluttered and aesthetically pleasing.
|
44 |
Make sure things are not overlapping unless explicitly stated otherwise.
|
|
|
45 |
You got this!! <3
|
46 |
"""
|
47 |
)
|
@@ -66,7 +67,7 @@ You got this!! <3
|
|
66 |
with open(code_filepath, "w") as f:
|
67 |
f.write(code)
|
68 |
|
69 |
-
# Prepare the Manim command with --media_dir flag
|
70 |
cmd = [
|
71 |
"manim",
|
72 |
"-qm",
|
@@ -75,7 +76,12 @@ You got this!! <3
|
|
75 |
code_filepath,
|
76 |
scene_name
|
77 |
]
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
# Construct the expected output path from Manim.
|
81 |
expected_dir = os.path.join(media_dir, "videos", code_filename.replace(".py", ""), "720p30")
|
@@ -86,7 +92,7 @@ You got this!! <3
|
|
86 |
# Move the video file to /tmp (to serve it from there)
|
87 |
tmp_video_path = os.path.join("/tmp", video_filename)
|
88 |
shutil.move(video_path_in_media, tmp_video_path)
|
89 |
-
# The code file is already in /tmp
|
90 |
|
91 |
# Schedule deletion of both files after 10 minutes (600 seconds)
|
92 |
def remove_files():
|
|
|
27 |
if not prompt:
|
28 |
return render_template("index.html")
|
29 |
|
30 |
+
max_retries = 3
|
31 |
attempt = 0
|
32 |
last_error = None
|
33 |
while attempt < max_retries:
|
|
|
42 |
Make sure to not use external images or resources other than default Manim, however you can use numpy or other default libraries.
|
43 |
Keep the scene uncluttered and aesthetically pleasing.
|
44 |
Make sure things are not overlapping unless explicitly stated otherwise.
|
45 |
+
It is crucial that the script works correctly on the first try, so make sure to think about the layout and storyboard and stuff of the scene.
|
46 |
You got this!! <3
|
47 |
"""
|
48 |
)
|
|
|
67 |
with open(code_filepath, "w") as f:
|
68 |
f.write(code)
|
69 |
|
70 |
+
# Prepare the Manim command with the --media_dir flag
|
71 |
cmd = [
|
72 |
"manim",
|
73 |
"-qm",
|
|
|
76 |
code_filepath,
|
77 |
scene_name
|
78 |
]
|
79 |
+
try:
|
80 |
+
subprocess.run(cmd, check=True, capture_output=True, text=True)
|
81 |
+
except subprocess.CalledProcessError as cpe:
|
82 |
+
# Log only if an error occurs from Manim
|
83 |
+
app.logger.error("Manim error output: %s", cpe.stderr)
|
84 |
+
raise Exception(f"Manim failed: {cpe.stderr}")
|
85 |
|
86 |
# Construct the expected output path from Manim.
|
87 |
expected_dir = os.path.join(media_dir, "videos", code_filename.replace(".py", ""), "720p30")
|
|
|
92 |
# Move the video file to /tmp (to serve it from there)
|
93 |
tmp_video_path = os.path.join("/tmp", video_filename)
|
94 |
shutil.move(video_path_in_media, tmp_video_path)
|
95 |
+
# The code file is already at code_filepath in /tmp.
|
96 |
|
97 |
# Schedule deletion of both files after 10 minutes (600 seconds)
|
98 |
def remove_files():
|