Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,12 @@ import torch
|
|
5 |
import spaces
|
6 |
|
7 |
from PIL import Image
|
8 |
-
from diffusers import QwenImageEditPipeline
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
import os
|
11 |
import base64
|
@@ -137,9 +142,13 @@ def api(prompt, img_list, model="qwen-vl-max-latest", kwargs={}):
|
|
137 |
# --- Model Loading ---
|
138 |
dtype = torch.bfloat16
|
139 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
140 |
-
|
141 |
-
# Load the model pipeline
|
142 |
pipe = QwenImageEditPipeline.from_pretrained("Qwen/Qwen-Image-Edit", torch_dtype=dtype).to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
# --- UI Constants and Helpers ---
|
145 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
5 |
import spaces
|
6 |
|
7 |
from PIL import Image
|
8 |
+
# from diffusers import QwenImageEditPipeline
|
9 |
+
|
10 |
+
from optimization import optimize_pipeline_
|
11 |
+
from qwenimage.pipeline_qwen_image_edit import QwenImageEditPipeline
|
12 |
+
from qwenimage.transformer_qwenimage import QwenImageTransformer2DModel
|
13 |
+
from qwenimage.qwen_fa3_processor import QwenDoubleStreamAttnProcessorFA3
|
14 |
|
15 |
import os
|
16 |
import base64
|
|
|
142 |
# --- Model Loading ---
|
143 |
dtype = torch.bfloat16
|
144 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
145 |
pipe = QwenImageEditPipeline.from_pretrained("Qwen/Qwen-Image-Edit", torch_dtype=dtype).to(device)
|
146 |
+
pipe.transformer.__class__ = QwenImageTransformer2DModel
|
147 |
+
pipe.transformer.set_attn_processor(QwenDoubleStreamAttnProcessorFA3())
|
148 |
+
|
149 |
+
|
150 |
+
# --- Ahead-of-time compilation ---
|
151 |
+
optimize_pipeline_(pipe, image=Image.new("RGB", (1024, 1024)), prompt="prompt")
|
152 |
|
153 |
# --- UI Constants and Helpers ---
|
154 |
MAX_SEED = np.iinfo(np.int32).max
|