Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,8 @@ from qwenimage.qwen_fa3_processor import QwenDoubleStreamAttnProcessorFA3
|
|
| 13 |
|
| 14 |
from huggingface_hub import InferenceClient
|
| 15 |
import math
|
|
|
|
|
|
|
| 16 |
|
| 17 |
import os
|
| 18 |
import base64
|
|
@@ -168,35 +170,46 @@ dtype = torch.bfloat16
|
|
| 168 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 169 |
|
| 170 |
# Scheduler configuration for Lightning
|
| 171 |
-
scheduler_config = {
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
}
|
| 187 |
-
|
| 188 |
-
# Initialize scheduler with Lightning config
|
| 189 |
-
scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config)
|
| 190 |
-
|
| 191 |
-
# Load the model pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
pipe = QwenImageEditPlusPipeline.from_pretrained("Qwen/Qwen-Image-Edit-2509",
|
| 193 |
-
scheduler=scheduler,
|
| 194 |
torch_dtype=dtype).to(device)
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
# Apply the same optimizations from the first version
|
| 202 |
pipe.transformer.__class__ = QwenImageTransformer2DModel
|
|
@@ -222,7 +235,7 @@ def infer(
|
|
| 222 |
seed=42,
|
| 223 |
randomize_seed=False,
|
| 224 |
true_guidance_scale=1.0,
|
| 225 |
-
num_inference_steps=
|
| 226 |
height=None,
|
| 227 |
width=None,
|
| 228 |
rewrite_prompt=True,
|
|
@@ -360,7 +373,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 360 |
minimum=1,
|
| 361 |
maximum=40,
|
| 362 |
step=1,
|
| 363 |
-
value=
|
| 364 |
)
|
| 365 |
|
| 366 |
height = gr.Slider(
|
|
|
|
| 13 |
|
| 14 |
from huggingface_hub import InferenceClient
|
| 15 |
import math
|
| 16 |
+
from huggingface_hub import hf_hub_download
|
| 17 |
+
from safetensors.torch import load_file
|
| 18 |
|
| 19 |
import os
|
| 20 |
import base64
|
|
|
|
| 170 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 171 |
|
| 172 |
# Scheduler configuration for Lightning
|
| 173 |
+
# scheduler_config = {
|
| 174 |
+
# "base_image_seq_len": 256,
|
| 175 |
+
# "base_shift": math.log(3),
|
| 176 |
+
# "invert_sigmas": False,
|
| 177 |
+
# "max_image_seq_len": 8192,
|
| 178 |
+
# "max_shift": math.log(3),
|
| 179 |
+
# "num_train_timesteps": 1000,
|
| 180 |
+
# "shift": 1.0,
|
| 181 |
+
# "shift_terminal": None,
|
| 182 |
+
# "stochastic_sampling": False,
|
| 183 |
+
# "time_shift_type": "exponential",
|
| 184 |
+
# "use_beta_sigmas": False,
|
| 185 |
+
# "use_dynamic_shifting": True,
|
| 186 |
+
# "use_exponential_sigmas": False,
|
| 187 |
+
# "use_karras_sigmas": False,
|
| 188 |
+
# }
|
| 189 |
+
|
| 190 |
+
# # Initialize scheduler with Lightning config
|
| 191 |
+
# scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config)
|
| 192 |
+
|
| 193 |
+
# # Load the model pipeline
|
| 194 |
+
# pipe = QwenImageEditPlusPipeline.from_pretrained("Qwen/Qwen-Image-Edit-2509",
|
| 195 |
+
# scheduler=scheduler,
|
| 196 |
+
# torch_dtype=dtype).to(device)
|
| 197 |
+
# pipe.load_lora_weights(
|
| 198 |
+
# "lightx2v/Qwen-Image-Lightning",
|
| 199 |
+
# weight_name="Qwen-Image-Edit-2509/Qwen-Image-Edit-2509-Lightning-8steps-V1.0-bf16.safetensors"
|
| 200 |
+
# )
|
| 201 |
+
# pipe.fuse_lora()
|
| 202 |
pipe = QwenImageEditPlusPipeline.from_pretrained("Qwen/Qwen-Image-Edit-2509",
|
| 203 |
+
# scheduler=scheduler,
|
| 204 |
torch_dtype=dtype).to(device)
|
| 205 |
+
weights_path = hf_hub_download(
|
| 206 |
+
repo_id="linoyts/Qwen-Image-Edit-Rapid-AIO",
|
| 207 |
+
filename="transformer/transformer_weights.safetensors",
|
| 208 |
+
repo_type="model"
|
| 209 |
+
)
|
| 210 |
+
state_dict = load_file(weights_path)
|
| 211 |
+
|
| 212 |
+
pipe.transformer.load_state_dict(state_dict, strict=False)
|
| 213 |
|
| 214 |
# Apply the same optimizations from the first version
|
| 215 |
pipe.transformer.__class__ = QwenImageTransformer2DModel
|
|
|
|
| 235 |
seed=42,
|
| 236 |
randomize_seed=False,
|
| 237 |
true_guidance_scale=1.0,
|
| 238 |
+
num_inference_steps=4,
|
| 239 |
height=None,
|
| 240 |
width=None,
|
| 241 |
rewrite_prompt=True,
|
|
|
|
| 373 |
minimum=1,
|
| 374 |
maximum=40,
|
| 375 |
step=1,
|
| 376 |
+
value=4,
|
| 377 |
)
|
| 378 |
|
| 379 |
height = gr.Slider(
|