Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ from fastapi import FastAPI
|
|
2 |
from fastapi.responses import FileResponse
|
3 |
import os
|
4 |
import subprocess
|
|
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
@@ -11,23 +12,38 @@ def read_root():
|
|
11 |
|
12 |
@app.get("/generate")
|
13 |
def generate_animation():
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
os.makedirs(output_dir, exist_ok=True)
|
20 |
-
|
21 |
-
#
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
return FileResponse(output_file, media_type="video/mp4", filename="example_scene.mp4")
|
32 |
else:
|
33 |
-
return {"
|
|
|
2 |
from fastapi.responses import FileResponse
|
3 |
import os
|
4 |
import subprocess
|
5 |
+
from manim import *
|
6 |
|
7 |
app = FastAPI()
|
8 |
|
|
|
12 |
|
13 |
@app.get("/generate")
|
14 |
def generate_animation():
|
15 |
+
class PointMovingOnShapes(Scene):
|
16 |
+
def construct(self):
|
17 |
+
# Define the circle and dot
|
18 |
+
circle = Circle(radius=1, color=BLUE)
|
19 |
+
dot = Dot()
|
20 |
+
dot2 = dot.copy().shift(RIGHT)
|
21 |
+
self.add(dot)
|
22 |
+
|
23 |
+
# Create a line
|
24 |
+
line = Line([3, 0, 0], [5, 0, 0])
|
25 |
+
self.add(line)
|
26 |
+
|
27 |
+
# Animate the circle, dot, and line
|
28 |
+
self.play(GrowFromCenter(circle))
|
29 |
+
self.play(Transform(dot, dot2))
|
30 |
+
self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)
|
31 |
+
self.play(Rotating(dot, about_point=[2, 0, 0]), run_time=1.5)
|
32 |
+
self.wait()
|
33 |
+
|
34 |
+
# Directory to save rendered video
|
35 |
+
output_dir = "/tmp/manim_output"
|
36 |
os.makedirs(output_dir, exist_ok=True)
|
37 |
+
|
38 |
+
# Rendering the scene to a video file
|
39 |
+
scene = PointMovingOnShapes()
|
40 |
+
scene.render(directory=output_dir)
|
41 |
+
|
42 |
+
# Path to the rendered video file (manim by default saves as .mp4)
|
43 |
+
video_path = os.path.join(output_dir, "media", "videos", "PointMovingOnShapes", "1080p60", "PointMovingOnShapes.mp4")
|
44 |
+
|
45 |
+
# Return the video file as a response
|
46 |
+
if os.path.exists(video_path):
|
47 |
+
return FileResponse(video_path)
|
|
|
48 |
else:
|
49 |
+
return {"message": "Error: Animation rendering failed."}
|