Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,56 +1,56 @@
|
|
| 1 |
# --- Configuration ---
|
| 2 |
MANIM_SCRIPT_FILE = "proof.py"
|
| 3 |
MANIM_SCENE_NAME = "PythagoreanTheorem"
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
def render_manim_video():
|
| 8 |
"""
|
| 9 |
-
|
| 10 |
-
|
| 11 |
"""
|
| 12 |
-
# 1. Clean up previous renders
|
| 13 |
-
if os.path.exists(
|
| 14 |
-
shutil.rmtree(
|
| 15 |
|
| 16 |
-
# 2.
|
| 17 |
os.makedirs(os.path.dirname(OUTPUT_VIDEO_PATH), exist_ok=True)
|
| 18 |
|
| 19 |
-
# 3. Construct the Manim command
|
| 20 |
command = [
|
| 21 |
"manim",
|
| 22 |
"-ql",
|
| 23 |
]
|
| 24 |
|
| 25 |
try:
|
| 26 |
-
#
|
| 27 |
process = subprocess.run(
|
| 28 |
command,
|
| 29 |
check=True,
|
| 30 |
)
|
| 31 |
print("Manim STDOUT:", process.stdout)
|
| 32 |
|
| 33 |
-
# 4.
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
return OUTPUT_VIDEO_PATH
|
| 38 |
else:
|
| 39 |
-
raise gr.Error("Video was not created. Check Manim
|
| 40 |
|
| 41 |
except subprocess.CalledProcessError as e:
|
| 42 |
-
|
| 43 |
print("Manim STDERR:", e.stderr)
|
| 44 |
raise gr.Error(f"Manim failed to render. Error: {e.stderr}")
|
| 45 |
except Exception as e:
|
| 46 |
-
raise gr.Error(f"
|
| 47 |
|
| 48 |
-
# --- Gradio
|
| 49 |
with gr.Blocks() as demo:
|
| 50 |
gr.Markdown("# Interactive Manim: Pythagorean Theorem Proof")
|
| 51 |
gr.Markdown(
|
| 52 |
outputs=[output_video]
|
| 53 |
)
|
| 54 |
|
| 55 |
-
# --- Launch ---
|
| 56 |
demo.launch(server_name="0.0.0.0", share=True)
|
|
|
|
| 1 |
# --- Configuration ---
|
| 2 |
MANIM_SCRIPT_FILE = "proof.py"
|
| 3 |
MANIM_SCENE_NAME = "PythagoreanTheorem"
|
| 4 |
+
OUTPUT_VIDEO_PATH = f"media/videos/proof/480p15/{MANIM_SCENE_NAME}.mp4"
|
| 5 |
+
|
| 6 |
|
| 7 |
def render_manim_video():
|
| 8 |
"""
|
| 9 |
+
This function runs the Manim command to render the video.
|
| 10 |
+
It cleans up old media files and returns the path to the new video.
|
| 11 |
"""
|
| 12 |
+
# 1. Clean up previous renders to avoid errors
|
| 13 |
+
if os.path.exists("media"):
|
| 14 |
+
shutil.rmtree("media")
|
| 15 |
|
| 16 |
+
# 2. Ensure output directory exists
|
| 17 |
os.makedirs(os.path.dirname(OUTPUT_VIDEO_PATH), exist_ok=True)
|
| 18 |
|
| 19 |
+
# 3. Construct and run the Manim command
|
| 20 |
command = [
|
| 21 |
"manim",
|
| 22 |
"-ql",
|
| 23 |
]
|
| 24 |
|
| 25 |
try:
|
| 26 |
+
# Execute the command
|
| 27 |
process = subprocess.run(
|
| 28 |
command,
|
| 29 |
check=True,
|
| 30 |
)
|
| 31 |
print("Manim STDOUT:", process.stdout)
|
| 32 |
|
| 33 |
+
# 4. Return the path to the generated video
|
| 34 |
+
if os.path.exists(OUTPUT_VIDEO_PATH):
|
| 35 |
+
|
| 36 |
+
|
| 37 |
return OUTPUT_VIDEO_PATH
|
| 38 |
else:
|
| 39 |
+
raise gr.Error("Video file was not created. Check the Manim logs.")
|
| 40 |
|
| 41 |
except subprocess.CalledProcessError as e:
|
| 42 |
+
# If the command fails, raise an error with the logs
|
| 43 |
print("Manim STDERR:", e.stderr)
|
| 44 |
raise gr.Error(f"Manim failed to render. Error: {e.stderr}")
|
| 45 |
except Exception as e:
|
| 46 |
+
raise gr.Error(f"An unexpected error occurred: {str(e)}")
|
| 47 |
|
| 48 |
+
# --- Create the Gradio Interface ---
|
| 49 |
with gr.Blocks() as demo:
|
| 50 |
gr.Markdown("# Interactive Manim: Pythagorean Theorem Proof")
|
| 51 |
gr.Markdown(
|
| 52 |
outputs=[output_video]
|
| 53 |
)
|
| 54 |
|
| 55 |
+
# --- Launch the App ---
|
| 56 |
demo.launch(server_name="0.0.0.0", share=True)
|