Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,42 @@
|
|
|
|
1 |
from diffusers import StableDiffusionPipeline
|
2 |
-
import os
|
3 |
import ffmpeg
|
|
|
4 |
|
5 |
-
|
|
|
6 |
|
7 |
def generate_video(prompt):
|
|
|
8 |
frames = []
|
9 |
-
for i in range(
|
10 |
image = model(prompt).images[0]
|
11 |
frame_path = f"frame_{i}.png"
|
12 |
image.save(frame_path)
|
13 |
frames.append(frame_path)
|
14 |
|
|
|
15 |
output_video = "output.mp4"
|
16 |
(
|
17 |
ffmpeg
|
18 |
-
.input("frame_%d.png", framerate=1)
|
19 |
.output(output_video)
|
20 |
.run(overwrite_output=True)
|
21 |
)
|
22 |
|
23 |
-
# Clean up
|
24 |
for frame in frames:
|
25 |
os.remove(frame)
|
26 |
|
27 |
-
return output_video
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
from diffusers import StableDiffusionPipeline
|
|
|
3 |
import ffmpeg
|
4 |
+
import os
|
5 |
|
6 |
+
# Load the Stable Diffusion model
|
7 |
+
model = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-lite")
|
8 |
|
9 |
def generate_video(prompt):
|
10 |
+
# Generate frames
|
11 |
frames = []
|
12 |
+
for i in range(5): # Generate 5 frames
|
13 |
image = model(prompt).images[0]
|
14 |
frame_path = f"frame_{i}.png"
|
15 |
image.save(frame_path)
|
16 |
frames.append(frame_path)
|
17 |
|
18 |
+
# Combine frames into a video
|
19 |
output_video = "output.mp4"
|
20 |
(
|
21 |
ffmpeg
|
22 |
+
.input("frame_%d.png", framerate=1) # Adjust framerate for longer/shorter videos
|
23 |
.output(output_video)
|
24 |
.run(overwrite_output=True)
|
25 |
)
|
26 |
|
27 |
+
# Clean up temporary frame files
|
28 |
for frame in frames:
|
29 |
os.remove(frame)
|
30 |
|
31 |
+
return output_video # Return the path to the video file
|
32 |
+
|
33 |
+
# Gradio interface
|
34 |
+
with gr.Blocks() as demo:
|
35 |
+
gr.Markdown("# AI Video Generator")
|
36 |
+
prompt_input = gr.Textbox(label="Enter your video prompt", placeholder="Type something creative...")
|
37 |
+
video_output = gr.File(label="Download Your Video")
|
38 |
+
generate_button = gr.Button("Generate Video")
|
39 |
+
|
40 |
+
generate_button.click(fn=generate_video, inputs=prompt_input, outputs=video_output)
|
41 |
+
|
42 |
+
demo.launch()
|