Update app.py
Browse files12346 unmodified lines11121314151617313 unmodified lines33133233333433533633733880 unmodified lines4194204214224234244254264274284294304314323 unmodified lines436437438439440441442443444445446447185 unmodified lines6336346356366376386399 unmodified lines649650651652653654655656import osimport spacesimport shutilimport subprocess6 unmodified linesimport gcimport uuidfrom tqdm import tqdmimport cv2import numpy as npimport torch313 unmodified linesquantize_(pipe.transformer_2, Float8DynamicActivationFloat8WeightConfig())torch._dynamo.reset()aoti.aoti_blocks_load(pipe.transformer, 'zerogpu-aoti/Wan2', variant='fp8da')aoti.aoti_blocks_load(pipe.transformer_2, 'zerogpu-aoti/Wan2', variant='fp8da')# pipe.vae.enable_slicing()# pipe.vae.enable_tiling()80 unmodified linesprogress):BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624BASE_STEP_DURATION = 15width, height = resized_image.sizefactor = num_frames * width * height / BASE_FRAMES_HEIGHT_WIDTHstep_duration = BASE_STEP_DURATION * factor ** 1.5gen_time = int(steps) * step_durationif guidance_scale > 1:gen_time = gen_time * 1.9frame_factor = frame_multiplier // FIXED_FPSif frame_factor > 1:3 unmodified linestotal_time = 15 + gen_timeif safe_mode:total_time = total_time * 1.20return total_time@spaces.GPU(duration=get_inference_duration)def run_inference(resized_image,processed_last_image,185 unmodified lineswith gr.Blocks(delete_cache=(3600, 10800)) as demo:gr.Markdown(model_title())gr.Markdown("#### ℹ️ **A Note on Performance:** This version prioritizes a straightforward setup over maximum speed, so performance may vary.")gr.Markdown("Run Wan 2.2 in just 4-8 steps, fp8 quantization & AoT compilation - compatible with 🧨 diffusers and ZeroGPU")with gr.Row():9 unmodified lines)safe_mode_checkbox = gr.Checkbox(label="🛠️ Safe Mode",value=False,info="Requests 20% extra processing time to try to prevent unfinished tasks when the server is busy.")with gr.Accordion("Advanced Settings", open=False):last_image_component = gr.Image(type="pil", label="Last Image (Optional)", sources=["upload", "clipboard"])12346 unmodified lines111213141516313 unmodified lines33033133233333433533633733833934034134234380 unmodified lines4244254264274284294304314324334344354364373 unmodified lines441442443444445446447448449450451452185 unmodified lines6386396406416426439 unmodified lines653654655656657658659660import os; os.system('pip install --upgrade --no-deps spaces')import spacesimport shutilimport subprocess6 unmodified linesimport gcimport uuidfrom tqdm import tqdmimport cv2import numpy as npimport torch313 unmodified linesquantize_(pipe.transformer_2, Float8DynamicActivationFloat8WeightConfig())torch._dynamo.reset()spaces.aoti_load(module=pipe.transformer,repo_id='cbensimon/WanTransformer3DModel-sm120-cu130-raa',)spaces.aoti_load(module=pipe.transformer_2,repo_id='cbensimon/WanTransformer3DModel-sm120-cu130-raa',)# pipe.vae.enable_slicing()# pipe.vae.enable_tiling()80 unmodified linesprogress):BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624BASE_STEP_DURATION = 5.width, height = resized_image.sizefactor = num_frames * width * height / BASE_FRAMES_HEIGHT_WIDTHstep_duration = BASE_STEP_DURATION * factor ** 1.5gen_time = int(steps) * step_durationif guidance_scale > 1:gen_time = gen_time * 2.4frame_factor = frame_multiplier // FIXED_FPSif frame_factor > 1:3 unmodified linestotal_time = 15 + gen_timeif safe_mode:total_time = total_time * 1.30return total_time@spaces.GPU(duration=get_inference_duration, size='xlarge')def run_inference(resized_image,processed_last_image,185 unmodified lineswith gr.Blocks(delete_cache=(3600, 10800)) as demo:gr.Markdown(model_title())gr.Markdown("Run Wan 2.2 in just 4-8 steps, fp8 quantization & AoT compilation - compatible with 🧨 diffusers and ZeroGPU")with gr.Row():9 unmodified lines)safe_mode_checkbox = gr.Checkbox(label="🛠️ Safe Mode",value=True,info="Requests 30% extra processing time to try to prevent unfinished tasks when the server is busy.")with gr.Accordion("Advanced Settings", open=False):last_image_component = gr.Image(type="pil", label="Last Image (Optional)", sources=["upload", "clipboard"])
app.py+15-11