Spaces:
Runtime error
Runtime error
Commit
·
ef4aa37
1
Parent(s):
d9bda94
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
from stability_sdk.api import Context
|
4 |
from stability_sdk.animation import AnimationArgs, Animator
|
@@ -111,14 +112,27 @@ def anim(f_promt, s_promt, stability_key, cadence_interp, width ,height ,sampler
|
|
111 |
if not os.path.exists(output_dir):
|
112 |
os.makedirs(output_dir)
|
113 |
# Render each frame of animation
|
|
|
114 |
images = []
|
115 |
for idx, frame in enumerate(animator.render()):
|
116 |
file_path = os.path.join(output_dir, f"frame_{idx:05d}.png")
|
117 |
frame.save(file_path)
|
118 |
print("Created frame at:"+file_path)
|
119 |
images.append(file_path)
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
with gr.Blocks() as demo:
|
124 |
gr.Markdown("Stability Animation")
|
|
|
1 |
import os
|
2 |
+
import cv2
|
3 |
import gradio as gr
|
4 |
from stability_sdk.api import Context
|
5 |
from stability_sdk.animation import AnimationArgs, Animator
|
|
|
112 |
if not os.path.exists(output_dir):
|
113 |
os.makedirs(output_dir)
|
114 |
# Render each frame of animation
|
115 |
+
# Render each frame of animation
|
116 |
images = []
|
117 |
for idx, frame in enumerate(animator.render()):
|
118 |
file_path = os.path.join(output_dir, f"frame_{idx:05d}.png")
|
119 |
frame.save(file_path)
|
120 |
print("Created frame at:"+file_path)
|
121 |
images.append(file_path)
|
122 |
+
|
123 |
+
# Define the codec using VideoWriter_fourcc() and create a VideoWriter object
|
124 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # or use 'XVID'
|
125 |
+
height, width, _ = cv2.imread(images[0]).shape # get the frame size from the first image
|
126 |
+
video_path = os.path.join(output_dir, 'output.mp4') # specify your output video file path here
|
127 |
+
out = cv2.VideoWriter(video_path, fourcc, fps, (width, height))
|
128 |
+
|
129 |
+
# Write each frame to the video file
|
130 |
+
for image_path in images:
|
131 |
+
frame = cv2.imread(image_path)
|
132 |
+
out.write(frame)
|
133 |
+
|
134 |
+
# Release the VideoWriter
|
135 |
+
out.release()
|
136 |
|
137 |
with gr.Blocks() as demo:
|
138 |
gr.Markdown("Stability Animation")
|