Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from diffusers import DiffusionPipeline
|
| 3 |
import torch
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import time
|
| 6 |
import warnings
|
|
@@ -30,23 +31,27 @@ def generate_video(prompt, num_frames=8, num_inference_steps=20):
|
|
| 30 |
|
| 31 |
# Generate with lower resolution and fewer frames for CPU
|
| 32 |
with torch.no_grad():
|
| 33 |
-
|
| 34 |
prompt,
|
| 35 |
num_frames=min(num_frames, 8), # Keep frames low for CPU
|
| 36 |
num_inference_steps=min(num_inference_steps, 20),
|
| 37 |
height=256, # Lower resolution
|
| 38 |
width=256
|
| 39 |
-
)
|
| 40 |
|
| 41 |
-
#
|
|
|
|
|
|
|
|
|
|
| 42 |
gif_path = "output.gif"
|
| 43 |
duration = max(1000 // 3, 100) # Minimum 100ms per frame
|
| 44 |
-
|
| 45 |
gif_path,
|
| 46 |
save_all=True,
|
| 47 |
-
append_images=
|
| 48 |
duration=duration,
|
| 49 |
-
loop=0
|
|
|
|
| 50 |
)
|
| 51 |
|
| 52 |
gen_time = time.time() - start_time
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from diffusers import DiffusionPipeline
|
| 3 |
import torch
|
| 4 |
+
import numpy as np
|
| 5 |
from PIL import Image
|
| 6 |
import time
|
| 7 |
import warnings
|
|
|
|
| 31 |
|
| 32 |
# Generate with lower resolution and fewer frames for CPU
|
| 33 |
with torch.no_grad():
|
| 34 |
+
output = generate_video.pipe(
|
| 35 |
prompt,
|
| 36 |
num_frames=min(num_frames, 8), # Keep frames low for CPU
|
| 37 |
num_inference_steps=min(num_inference_steps, 20),
|
| 38 |
height=256, # Lower resolution
|
| 39 |
width=256
|
| 40 |
+
)
|
| 41 |
|
| 42 |
+
# Convert numpy arrays to PIL Images
|
| 43 |
+
frames = [Image.fromarray((frame * 255).astype(np.uint8)) for frame in output.frames]
|
| 44 |
+
|
| 45 |
+
# Create GIF
|
| 46 |
gif_path = "output.gif"
|
| 47 |
duration = max(1000 // 3, 100) # Minimum 100ms per frame
|
| 48 |
+
frames[0].save(
|
| 49 |
gif_path,
|
| 50 |
save_all=True,
|
| 51 |
+
append_images=frames[1:],
|
| 52 |
duration=duration,
|
| 53 |
+
loop=0,
|
| 54 |
+
save_format='GIF'
|
| 55 |
)
|
| 56 |
|
| 57 |
gen_time = time.time() - start_time
|