Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import os
|
|
8 |
# from diffusers import QwenImageEditInpaintPipeline
|
9 |
from optimization import optimize_pipeline_
|
10 |
from diffusers.utils import load_image
|
|
|
11 |
from qwenimage.pipeline_qwenimage_edit_inpaint import QwenImageEditInpaintPipeline
|
12 |
from qwenimage.transformer_qwenimage import QwenImageTransformer2DModel
|
13 |
from qwenimage.qwen_fa3_processor import QwenDoubleStreamAttnProcessorFA3
|
@@ -21,14 +22,44 @@ MAX_SEED = np.iinfo(np.int32).max
|
|
21 |
MAX_IMAGE_SIZE = 2048
|
22 |
|
23 |
# Initialize Qwen Image Edit pipeline
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
pipe.transformer.__class__ = QwenImageTransformer2DModel
|
26 |
pipe.transformer.set_attn_processor(QwenDoubleStreamAttnProcessorFA3())
|
27 |
|
28 |
-
dummy_mask = load_image("https://github.com/Trgtuan10/Image_storage/blob/main/mask_cat.png?raw=true")
|
29 |
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
32 |
|
33 |
@spaces.GPU(duration=120)
|
34 |
def infer(edit_images, prompt, negative_prompt="", seed=42, randomize_seed=False, strength=1.0, num_inference_steps=35, true_cfg_scale=4.0, progress=gr.Progress(track_tqdm=True)):
|
@@ -138,16 +169,16 @@ with gr.Blocks(css=css) as demo:
|
|
138 |
minimum=1.0,
|
139 |
maximum=20.0,
|
140 |
step=0.5,
|
141 |
-
value=
|
142 |
info="Classifier-free guidance scale"
|
143 |
)
|
144 |
|
145 |
num_inference_steps = gr.Slider(
|
146 |
label="Number of inference steps",
|
147 |
minimum=10,
|
148 |
-
maximum=
|
149 |
step=1,
|
150 |
-
value=
|
151 |
)
|
152 |
|
153 |
gr.on(
|
|
|
8 |
# from diffusers import QwenImageEditInpaintPipeline
|
9 |
from optimization import optimize_pipeline_
|
10 |
from diffusers.utils import load_image
|
11 |
+
from diffusers import FlowMatchEulerDiscreteScheduler
|
12 |
from qwenimage.pipeline_qwenimage_edit_inpaint import QwenImageEditInpaintPipeline
|
13 |
from qwenimage.transformer_qwenimage import QwenImageTransformer2DModel
|
14 |
from qwenimage.qwen_fa3_processor import QwenDoubleStreamAttnProcessorFA3
|
|
|
22 |
MAX_IMAGE_SIZE = 2048
|
23 |
|
24 |
# Initialize Qwen Image Edit pipeline
|
25 |
+
# Scheduler configuration for Lightning
|
26 |
+
scheduler_config = {
|
27 |
+
"base_image_seq_len": 256,
|
28 |
+
"base_shift": math.log(3),
|
29 |
+
"invert_sigmas": False,
|
30 |
+
"max_image_seq_len": 8192,
|
31 |
+
"max_shift": math.log(3),
|
32 |
+
"num_train_timesteps": 1000,
|
33 |
+
"shift": 1.0,
|
34 |
+
"shift_terminal": None,
|
35 |
+
"stochastic_sampling": False,
|
36 |
+
"time_shift_type": "exponential",
|
37 |
+
"use_beta_sigmas": False,
|
38 |
+
"use_dynamic_shifting": True,
|
39 |
+
"use_exponential_sigmas": False,
|
40 |
+
"use_karras_sigmas": False,
|
41 |
+
}
|
42 |
+
|
43 |
+
# Initialize scheduler with Lightning config
|
44 |
+
scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config)
|
45 |
+
|
46 |
+
|
47 |
+
pipe = QwenImageEditInpaintPipeline.from_pretrained("Qwen/Qwen-Image-Edit", scheduler=scheduler, torch_dtype=torch.bfloat16).to("cuda")
|
48 |
+
pipe.load_lora_weights(
|
49 |
+
"lightx2v/Qwen-Image-Lightning",
|
50 |
+
weight_name="Qwen-Image-Lightning-8steps-V1.1.safetensors"
|
51 |
+
)
|
52 |
+
pipe.fuse_lora()
|
53 |
+
|
54 |
pipe.transformer.__class__ = QwenImageTransformer2DModel
|
55 |
pipe.transformer.set_attn_processor(QwenDoubleStreamAttnProcessorFA3())
|
56 |
|
|
|
57 |
|
58 |
+
|
59 |
+
# dummy_mask = load_image("https://github.com/Trgtuan10/Image_storage/blob/main/mask_cat.png?raw=true")
|
60 |
+
|
61 |
+
# # --- Ahead-of-time compilation ---
|
62 |
+
# optimize_pipeline_(pipe, image=Image.new("RGB", (1328, 1328)), prompt="prompt", mask_image=dummy_mask)
|
63 |
|
64 |
@spaces.GPU(duration=120)
|
65 |
def infer(edit_images, prompt, negative_prompt="", seed=42, randomize_seed=False, strength=1.0, num_inference_steps=35, true_cfg_scale=4.0, progress=gr.Progress(track_tqdm=True)):
|
|
|
169 |
minimum=1.0,
|
170 |
maximum=20.0,
|
171 |
step=0.5,
|
172 |
+
value=1.0,
|
173 |
info="Classifier-free guidance scale"
|
174 |
)
|
175 |
|
176 |
num_inference_steps = gr.Slider(
|
177 |
label="Number of inference steps",
|
178 |
minimum=10,
|
179 |
+
maximum=50,
|
180 |
step=1,
|
181 |
+
value=8,
|
182 |
)
|
183 |
|
184 |
gr.on(
|