Spaces:
Running
on
Zero
Running
on
Zero
Add optimizations
Browse files
app.py
CHANGED
|
@@ -8,9 +8,15 @@ import json
|
|
| 8 |
|
| 9 |
from PIL import Image
|
| 10 |
from diffusers import QwenImageEditPipeline, FlowMatchEulerDiscreteScheduler
|
|
|
|
| 11 |
from huggingface_hub import InferenceClient
|
| 12 |
import math
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# --- Prompt Enhancement using Hugging Face InferenceClient ---
|
| 15 |
def polish_prompt_hf(original_prompt, system_prompt):
|
| 16 |
"""
|
|
@@ -159,7 +165,7 @@ scheduler_config = {
|
|
| 159 |
scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config)
|
| 160 |
|
| 161 |
# Load the edit pipeline with Lightning scheduler
|
| 162 |
-
pipe =
|
| 163 |
"Qwen/Qwen-Image-Edit",
|
| 164 |
scheduler=scheduler,
|
| 165 |
torch_dtype=dtype
|
|
@@ -177,6 +183,13 @@ except Exception as e:
|
|
| 177 |
print(f"Warning: Could not load Lightning LoRA weights: {e}")
|
| 178 |
print("Continuing with base model...")
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
# --- UI Constants and Helpers ---
|
| 181 |
MAX_SEED = np.iinfo(np.int32).max
|
| 182 |
|
|
|
|
| 8 |
|
| 9 |
from PIL import Image
|
| 10 |
from diffusers import QwenImageEditPipeline, FlowMatchEulerDiscreteScheduler
|
| 11 |
+
|
| 12 |
from huggingface_hub import InferenceClient
|
| 13 |
import math
|
| 14 |
|
| 15 |
+
from optimization import optimize_pipeline_
|
| 16 |
+
from qwenimage.pipeline_qwen_image_edit import QwenImageEditPipeline as QwenImageEditPipelineCustom
|
| 17 |
+
from qwenimage.transformer_qwenimage import QwenImageTransformer2DModel
|
| 18 |
+
from qwenimage.qwen_fa3_processor import QwenDoubleStreamAttnProcessorFA3
|
| 19 |
+
|
| 20 |
# --- Prompt Enhancement using Hugging Face InferenceClient ---
|
| 21 |
def polish_prompt_hf(original_prompt, system_prompt):
|
| 22 |
"""
|
|
|
|
| 165 |
scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config)
|
| 166 |
|
| 167 |
# Load the edit pipeline with Lightning scheduler
|
| 168 |
+
pipe = QwenImageEditPipelineCustom.from_pretrained(
|
| 169 |
"Qwen/Qwen-Image-Edit",
|
| 170 |
scheduler=scheduler,
|
| 171 |
torch_dtype=dtype
|
|
|
|
| 183 |
print(f"Warning: Could not load Lightning LoRA weights: {e}")
|
| 184 |
print("Continuing with base model...")
|
| 185 |
|
| 186 |
+
# Apply the same optimizations from the first version
|
| 187 |
+
pipe.transformer.__class__ = QwenImageTransformer2DModel
|
| 188 |
+
pipe.transformer.set_attn_processor(QwenDoubleStreamAttnProcessorFA3())
|
| 189 |
+
|
| 190 |
+
# --- Ahead-of-time compilation ---
|
| 191 |
+
optimize_pipeline_(pipe, image=Image.new("RGB", (1024, 1024)), prompt="prompt")
|
| 192 |
+
|
| 193 |
# --- UI Constants and Helpers ---
|
| 194 |
MAX_SEED = np.iinfo(np.int32).max
|
| 195 |
|