Spaces:
Build error
Build error
| # --- Configuration --- | |
| MANIM_SCRIPT_FILE = "proof.py" | |
| MANIM_SCENE_NAME = "PythagoreanTheorem" | |
| OUTPUT_VIDEO_PATH = f"media/videos/proof/480p15/{MANIM_SCENE_NAME}.mp4" | |
| def render_manim_video(): | |
| """ | |
| This function runs the Manim command to render the video. | |
| It cleans up old media files and returns the path to the new video. | |
| """ | |
| # 1. Clean up previous renders to avoid errors | |
| if os.path.exists("media"): | |
| shutil.rmtree("media") | |
| # 2. Ensure output directory exists | |
| os.makedirs(os.path.dirname(OUTPUT_VIDEO_PATH), exist_ok=True) | |
| # 3. Construct and run the Manim command | |
| command = [ | |
| "manim", | |
| "-ql", | |
| ] | |
| try: | |
| # Execute the command | |
| process = subprocess.run( | |
| command, | |
| check=True, | |
| ) | |
| print("Manim STDOUT:", process.stdout) | |
| # 4. Return the path to the generated video | |
| if os.path.exists(OUTPUT_VIDEO_PATH): | |
| return OUTPUT_VIDEO_PATH | |
| else: | |
| raise gr.Error("Video file was not created. Check the Manim logs.") | |
| except subprocess.CalledProcessError as e: | |
| # If the command fails, raise an error with the logs | |
| print("Manim STDERR:", e.stderr) | |
| raise gr.Error(f"Manim failed to render. Error: {e.stderr}") | |
| except Exception as e: | |
| raise gr.Error(f"An unexpected error occurred: {str(e)}") | |
| # --- Create the Gradio Interface --- | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Interactive Manim: Pythagorean Theorem Proof") | |
| gr.Markdown( | |
| outputs=[output_video] | |
| ) | |
| # --- Launch the App --- | |
| demo.launch(server_name="0.0.0.0", share=True) |