Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,9 +23,28 @@ import json
|
|
| 23 |
import boto3
|
| 24 |
from io import BytesIO
|
| 25 |
from diffusers.utils import load_image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
MODEL_ID = "Wan-AI/Wan2.2-I2V-A14B-Diffusers"
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
pipe = WanImageToVideoPipeline.from_pretrained(MODEL_ID,
|
| 30 |
transformer=WanTransformer3DModel.from_pretrained('cbensimon/Wan2.2-I2V-A14B-bf16-Diffusers',
|
| 31 |
subfolder='transformer',
|
|
@@ -40,19 +59,20 @@ pipe = WanImageToVideoPipeline.from_pretrained(MODEL_ID,
|
|
| 40 |
torch_dtype=torch.bfloat16,
|
| 41 |
).to('cuda')
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
SLIDER_MIN_H, SLIDER_MAX_H = 128, 896
|
| 50 |
-
SLIDER_MIN_W, SLIDER_MAX_W = 128, 896
|
| 51 |
-
MAX_SEED = np.iinfo(np.int32).max
|
| 52 |
|
| 53 |
-
FIXED_FPS = 24
|
| 54 |
-
MIN_FRAMES_MODEL = 8
|
| 55 |
-
MAX_FRAMES_MODEL = 81
|
| 56 |
|
| 57 |
default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"
|
| 58 |
default_negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards, watermark, text, signature"
|
|
|
|
| 23 |
import boto3
|
| 24 |
from io import BytesIO
|
| 25 |
from diffusers.utils import load_image
|
| 26 |
+
import random
|
| 27 |
+
import gc
|
| 28 |
+
from optimization import optimize_pipeline_
|
| 29 |
+
|
| 30 |
|
| 31 |
MODEL_ID = "Wan-AI/Wan2.2-I2V-A14B-Diffusers"
|
| 32 |
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
MOD_VALUE = 32
|
| 36 |
+
DEFAULT_H_SLIDER_VALUE = 512
|
| 37 |
+
DEFAULT_W_SLIDER_VALUE = 896
|
| 38 |
+
NEW_FORMULA_MAX_AREA = 480.0 * 832.0
|
| 39 |
+
|
| 40 |
+
SLIDER_MIN_H, SLIDER_MAX_H = 128, 896
|
| 41 |
+
SLIDER_MIN_W, SLIDER_MAX_W = 128, 896
|
| 42 |
+
MAX_SEED = np.iinfo(np.int32).max
|
| 43 |
+
|
| 44 |
+
FIXED_FPS = 24
|
| 45 |
+
MIN_FRAMES_MODEL = 8
|
| 46 |
+
MAX_FRAMES_MODEL = 81
|
| 47 |
+
|
| 48 |
pipe = WanImageToVideoPipeline.from_pretrained(MODEL_ID,
|
| 49 |
transformer=WanTransformer3DModel.from_pretrained('cbensimon/Wan2.2-I2V-A14B-bf16-Diffusers',
|
| 50 |
subfolder='transformer',
|
|
|
|
| 59 |
torch_dtype=torch.bfloat16,
|
| 60 |
).to('cuda')
|
| 61 |
|
| 62 |
+
for i in range(3):
|
| 63 |
+
gc.collect()
|
| 64 |
+
torch.cuda.synchronize()
|
| 65 |
+
torch.cuda.empty_cache()
|
| 66 |
|
| 67 |
+
optimize_pipeline_(pipe,
|
| 68 |
+
image=Image.new('RGB', (DEFAULT_W_SLIDER_VALUE, DEFAULT_H_SLIDER_VALUE)),
|
| 69 |
+
prompt='prompt',
|
| 70 |
+
height=DEFAULT_H_SLIDER_VALUE,
|
| 71 |
+
width=DEFAULT_W_SLIDER_VALUE,
|
| 72 |
+
num_frames=MAX_FRAMES_MODEL,
|
| 73 |
+
)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
| 75 |
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"
|
| 78 |
default_negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards, watermark, text, signature"
|