Spaces:
Running
Running
OmPrakashSingh1704
commited on
Commit
·
c8ca6fe
1
Parent(s):
a52084a
options/Video_model/Model.py
CHANGED
@@ -3,18 +3,33 @@ from diffusers import StableVideoDiffusionPipeline
|
|
3 |
from diffusers.utils import load_image, export_to_video
|
4 |
from PIL import Image
|
5 |
|
6 |
-
|
|
|
7 |
|
|
|
8 |
pipeline = StableVideoDiffusionPipeline.from_pretrained(
|
9 |
"stabilityai/stable-video-diffusion-img2vid-xt-1-1", torch_dtype=torch.float32
|
10 |
).to(device)
|
11 |
-
pipeline.enable_model_cpu_offload()
|
12 |
|
|
|
|
|
|
|
|
|
|
|
13 |
def Video(image):
|
14 |
image = Image.fromarray(image)
|
15 |
image = image.resize((1024, 576))
|
16 |
|
|
|
17 |
generator = torch.manual_seed(42)
|
|
|
|
|
|
|
|
|
|
|
18 |
frames = pipeline(image, decode_chunk_size=8, generator=generator).frames[0]
|
|
|
|
|
19 |
export_to_video(frames, "generated.mp4", fps=7)
|
|
|
20 |
return "generated.mp4"
|
|
|
3 |
from diffusers.utils import load_image, export_to_video
|
4 |
from PIL import Image
|
5 |
|
6 |
+
# Check if CUDA (GPU) is available, otherwise use CPU
|
7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
|
9 |
+
# Load the pipeline and move it to the appropriate device (GPU or CPU)
|
10 |
pipeline = StableVideoDiffusionPipeline.from_pretrained(
|
11 |
"stabilityai/stable-video-diffusion-img2vid-xt-1-1", torch_dtype=torch.float32
|
12 |
).to(device)
|
|
|
13 |
|
14 |
+
# Enable model offloading if using the CPU
|
15 |
+
if device == "cpu":
|
16 |
+
pipeline.enable_model_cpu_offload()
|
17 |
+
|
18 |
+
# Function to generate the video
|
19 |
def Video(image):
|
20 |
image = Image.fromarray(image)
|
21 |
image = image.resize((1024, 576))
|
22 |
|
23 |
+
# Set random seed for reproducibility
|
24 |
generator = torch.manual_seed(42)
|
25 |
+
|
26 |
+
# Ensure the image is moved to the appropriate device (GPU or CPU)
|
27 |
+
image = image.to(device)
|
28 |
+
|
29 |
+
# Generate the video frames
|
30 |
frames = pipeline(image, decode_chunk_size=8, generator=generator).frames[0]
|
31 |
+
|
32 |
+
# Export the frames to a video file
|
33 |
export_to_video(frames, "generated.mp4", fps=7)
|
34 |
+
|
35 |
return "generated.mp4"
|
options/Video_model/__pycache__/Model.cpython-310.pyc
CHANGED
Binary files a/options/Video_model/__pycache__/Model.cpython-310.pyc and b/options/Video_model/__pycache__/Model.cpython-310.pyc differ
|
|