Spaces:
Running
Running
OmPrakashSingh1704
commited on
Commit
·
3039940
1
Parent(s):
b34b866
options/Video_model/Model.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import torch,os,
|
2 |
from diffusers import StableVideoDiffusionPipeline
|
3 |
from diffusers.utils import load_image, export_to_video
|
4 |
from PIL import Image
|
@@ -7,6 +7,12 @@ login(token=os.getenv("TOKEN"))
|
|
7 |
# Check if CUDA (GPU) is available, otherwise use CPU
|
8 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Function to generate the video
|
12 |
def Video(image):
|
@@ -36,6 +42,6 @@ def Video(image):
|
|
36 |
frames = pipeline(image, decode_chunk_size=8, generator=generator).frames[0]
|
37 |
path="generated.mp4"
|
38 |
# Export the frames to a video file
|
39 |
-
|
40 |
-
vid=cv2.VideoCapture(path)
|
41 |
-
return
|
|
|
1 |
+
import torch,os,imageio
|
2 |
from diffusers import StableVideoDiffusionPipeline
|
3 |
from diffusers.utils import load_image, export_to_video
|
4 |
from PIL import Image
|
|
|
7 |
# Check if CUDA (GPU) is available, otherwise use CPU
|
8 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
|
10 |
+
def save_video(frames, save_path, fps, quality=9):
|
11 |
+
writer = imageio.get_writer(save_path, fps=fps, quality=quality)
|
12 |
+
for frame in frames:
|
13 |
+
frame = np.array(frame)
|
14 |
+
writer.append_data(frame)
|
15 |
+
writer.close()
|
16 |
|
17 |
# Function to generate the video
|
18 |
def Video(image):
|
|
|
42 |
frames = pipeline(image, decode_chunk_size=8, generator=generator).frames[0]
|
43 |
path="generated.mp4"
|
44 |
# Export the frames to a video file
|
45 |
+
save_video(frames, path, fps=7)
|
46 |
+
# vid=cv2.VideoCapture(path)
|
47 |
+
return path
|
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
|
|