Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
"""
|
2 |
Copyright NewGenAI
|
3 |
Code can't be included in commercial app used for monetary gain. No derivative code allowed.
|
@@ -10,6 +11,7 @@ import time
|
|
10 |
from datetime import datetime
|
11 |
import os
|
12 |
|
|
|
13 |
from diffusers.utils import export_to_video
|
14 |
from diffusers import LTXImageToVideoPipeline
|
15 |
from transformers import T5EncoderModel, T5Tokenizer
|
@@ -144,20 +146,24 @@ pipe = LTXImageToVideoPipeline.from_single_file(
|
|
144 |
)
|
145 |
pipe.enable_model_cpu_offload()
|
146 |
|
|
|
147 |
def generate_video(image, prompt, negative_prompt, height, width, num_frames, num_inference_steps, fps, seed):
|
148 |
if seed == 0:
|
149 |
seed = random.randint(0, 999999)
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
161 |
|
162 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
163 |
filename = f"{prompt[:10]}_{timestamp}.mp4"
|
|
|
1 |
+
import spaces
|
2 |
"""
|
3 |
Copyright NewGenAI
|
4 |
Code can't be included in commercial app used for monetary gain. No derivative code allowed.
|
|
|
11 |
from datetime import datetime
|
12 |
import os
|
13 |
|
14 |
+
import torch
|
15 |
from diffusers.utils import export_to_video
|
16 |
from diffusers import LTXImageToVideoPipeline
|
17 |
from transformers import T5EncoderModel, T5Tokenizer
|
|
|
146 |
)
|
147 |
pipe.enable_model_cpu_offload()
|
148 |
|
149 |
+
@spaces.GPU()
|
150 |
def generate_video(image, prompt, negative_prompt, height, width, num_frames, num_inference_steps, fps, seed):
|
151 |
if seed == 0:
|
152 |
seed = random.randint(0, 999999)
|
153 |
+
|
154 |
+
torch.cuda.synchronize()
|
155 |
+
torch.cuda.empty_cache()
|
156 |
+
with torch.inference_mode():
|
157 |
+
video = pipe(
|
158 |
+
image=image,
|
159 |
+
prompt=prompt,
|
160 |
+
negative_prompt=negative_prompt,
|
161 |
+
width=width,
|
162 |
+
height=height,
|
163 |
+
num_frames=num_frames,
|
164 |
+
num_inference_steps=num_inference_steps,
|
165 |
+
generator=torch.Generator(device='cuda').manual_seed(seed),
|
166 |
+
).frames[0]
|
167 |
|
168 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
169 |
filename = f"{prompt[:10]}_{timestamp}.mp4"
|