Update app.py
Browse files
app.py
CHANGED
@@ -31,14 +31,14 @@ def index():
|
|
31 |
ai_response = client.models.generate_content(
|
32 |
model="gemini-2.0-flash-lite-preview-02-05",
|
33 |
contents=f"""You are 'Manimator', an expert Manim animator and coder.
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
)
|
43 |
|
44 |
# Extract the Python code block from the AI response
|
@@ -63,10 +63,15 @@ def index():
|
|
63 |
with open(code_filename, "w") as f:
|
64 |
f.write(code)
|
65 |
|
66 |
-
#
|
|
|
|
|
|
|
|
|
67 |
cmd = [
|
68 |
"manim",
|
69 |
"-qm",
|
|
|
70 |
"-o", video_filename,
|
71 |
code_filename,
|
72 |
scene_name
|
@@ -76,13 +81,21 @@ def index():
|
|
76 |
print("Manim stdout:", result.stdout)
|
77 |
print("Manim stderr:", result.stderr)
|
78 |
|
79 |
-
# Construct the expected output path from Manim
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
# Verify that Manim produced the expected video file
|
82 |
if not os.path.exists(video_path_in_media):
|
83 |
raise Exception("Manim did not produce the expected output file.")
|
84 |
|
85 |
-
# Move both the video and the generated code file to /tmp (
|
86 |
tmp_video_path = os.path.join("/tmp", video_filename)
|
87 |
shutil.move(video_path_in_media, tmp_video_path)
|
88 |
|
|
|
31 |
ai_response = client.models.generate_content(
|
32 |
model="gemini-2.0-flash-lite-preview-02-05",
|
33 |
contents=f"""You are 'Manimator', an expert Manim animator and coder.
|
34 |
+
If anyone asks, your name is Manimator and you are a helpful video generator, and say nothing else but that.
|
35 |
+
The user wants you to code this: {prompt}.
|
36 |
+
Plan out in chain of thought what you are going to do first, then give the final code output in ```python``` codeblock.
|
37 |
+
Make sure to not use external images or resources other than default Manim, however you can use numpy or other default libraries.
|
38 |
+
Keep the scene uncluttered and aesthetically pleasing.
|
39 |
+
Make sure things are not overlapping unless explicitly stated otherwise.
|
40 |
+
You got this!! <3
|
41 |
+
"""
|
42 |
)
|
43 |
|
44 |
# Extract the Python code block from the AI response
|
|
|
63 |
with open(code_filename, "w") as f:
|
64 |
f.write(code)
|
65 |
|
66 |
+
# Set a dedicated media directory for Manim output in /tmp
|
67 |
+
media_dir = os.path.join("/tmp", "manim_media")
|
68 |
+
os.makedirs(media_dir, exist_ok=True)
|
69 |
+
|
70 |
+
# Prepare the Manim command with the --media_dir flag
|
71 |
cmd = [
|
72 |
"manim",
|
73 |
"-qm",
|
74 |
+
"--media_dir", media_dir,
|
75 |
"-o", video_filename,
|
76 |
code_filename,
|
77 |
scene_name
|
|
|
81 |
print("Manim stdout:", result.stdout)
|
82 |
print("Manim stderr:", result.stderr)
|
83 |
|
84 |
+
# Construct the expected output path from Manim.
|
85 |
+
# With --media_dir set, Manim should write the video to:
|
86 |
+
# {media_dir}/videos/<code_filename_without_.py>/720p30/<video_filename>
|
87 |
+
video_path_in_media = os.path.join(
|
88 |
+
media_dir,
|
89 |
+
"videos",
|
90 |
+
code_filename.replace(".py", ""),
|
91 |
+
"720p30",
|
92 |
+
video_filename
|
93 |
+
)
|
94 |
# Verify that Manim produced the expected video file
|
95 |
if not os.path.exists(video_path_in_media):
|
96 |
raise Exception("Manim did not produce the expected output file.")
|
97 |
|
98 |
+
# Move both the video and the generated code file to /tmp (a writable location)
|
99 |
tmp_video_path = os.path.join("/tmp", video_filename)
|
100 |
shutil.move(video_path_in_media, tmp_video_path)
|
101 |
|