Update app.py
Browse files
app.py
CHANGED
@@ -15,10 +15,14 @@ import random
|
|
15 |
token = os.environ['HF_TOKEN']
|
16 |
login(token=token)
|
17 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
|
|
|
18 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-video-diffusion-img2vid-xt-1-1")
|
19 |
#pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
20 |
-
|
21 |
pipe.enable_xformers_memory_efficient_attention()
|
|
|
|
|
22 |
|
23 |
max_64_bit_int = 2**63 - 1
|
24 |
|
@@ -40,7 +44,7 @@ def sample(
|
|
40 |
if(randomize_seed):
|
41 |
seed = random.randint(0, max_64_bit_int)
|
42 |
generator = torch.manual_seed(seed)
|
43 |
-
|
44 |
os.makedirs(output_folder, exist_ok=True)
|
45 |
base_count = len(glob(os.path.join(output_folder, "*.mp4")))
|
46 |
video_path = os.path.join(output_folder, f"{base_count:06d}.mp4")
|
@@ -48,7 +52,7 @@ def sample(
|
|
48 |
frames = pipe(image, decode_chunk_size=decoding_t, generator=generator, motion_bucket_id=motion_bucket_id, noise_aug_strength=0.1, num_frames=25).frames[0]
|
49 |
export_to_video(frames, video_path, fps=fps_id)
|
50 |
torch.manual_seed(seed)
|
51 |
-
|
52 |
return video_path, seed
|
53 |
|
54 |
def resize_image(image, output_size=(1024, 578)):
|
@@ -80,6 +84,7 @@ def resize_image(image, output_size=(1024, 578)):
|
|
80 |
|
81 |
# Crop the image
|
82 |
cropped_image = resized_image.crop((left, top, right, bottom))
|
|
|
83 |
return cropped_image
|
84 |
|
85 |
with gr.Blocks() as demo:
|
|
|
15 |
token = os.environ['HF_TOKEN']
|
16 |
login(token=token)
|
17 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
18 |
+
torch.cuda.max_memory_allocated(device=device)
|
19 |
+
torch.cuda.empty_cache()
|
20 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-video-diffusion-img2vid-xt-1-1")
|
21 |
#pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
22 |
+
|
23 |
pipe.enable_xformers_memory_efficient_attention()
|
24 |
+
pipe = pipe.to(device)
|
25 |
+
torch.cuda.empty_cache()
|
26 |
|
27 |
max_64_bit_int = 2**63 - 1
|
28 |
|
|
|
44 |
if(randomize_seed):
|
45 |
seed = random.randint(0, max_64_bit_int)
|
46 |
generator = torch.manual_seed(seed)
|
47 |
+
torch.cuda.empty_cache()
|
48 |
os.makedirs(output_folder, exist_ok=True)
|
49 |
base_count = len(glob(os.path.join(output_folder, "*.mp4")))
|
50 |
video_path = os.path.join(output_folder, f"{base_count:06d}.mp4")
|
|
|
52 |
frames = pipe(image, decode_chunk_size=decoding_t, generator=generator, motion_bucket_id=motion_bucket_id, noise_aug_strength=0.1, num_frames=25).frames[0]
|
53 |
export_to_video(frames, video_path, fps=fps_id)
|
54 |
torch.manual_seed(seed)
|
55 |
+
torch.cuda.empty_cache()
|
56 |
return video_path, seed
|
57 |
|
58 |
def resize_image(image, output_size=(1024, 578)):
|
|
|
84 |
|
85 |
# Crop the image
|
86 |
cropped_image = resized_image.crop((left, top, right, bottom))
|
87 |
+
torch.cuda.empty_cache()
|
88 |
return cropped_image
|
89 |
|
90 |
with gr.Blocks() as demo:
|