tommy24 commited on
Commit
b390c67
·
verified ·
1 Parent(s): ff5de89

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.responses import FileResponse
3
+ import os
4
+ import subprocess
5
+
6
+ app = FastAPI()
7
+
8
+ @app.get("/")
9
+ def read_root():
10
+ return {"message": "Welcome to the Manim API on HuggingFace!"}
11
+
12
+ @app.get("/generate")
13
+ def generate_animation():
14
+ # Define file paths
15
+ output_dir = "media"
16
+ output_file = os.path.join(output_dir, "ExampleScene.mp4")
17
+
18
+ # Ensure output directory exists
19
+ os.makedirs(output_dir, exist_ok=True)
20
+
21
+ # Run the Manim command
22
+ subprocess.run([
23
+ "manim",
24
+ "-pql", "example_scene.py", # 'l' for low quality (quick render)
25
+ "ExampleScene",
26
+ "--media_dir", output_dir
27
+ ])
28
+
29
+ # Check if the file exists and return
30
+ if os.path.exists(output_file):
31
+ return FileResponse(output_file, media_type="video/mp4", filename="example_scene.mp4")
32
+ else:
33
+ return {"error": "Animation generation failed!"}