LPX55 commited on
Commit
10cb4f7
·
verified ·
1 Parent(s): 72e5f46

Update app_local.py

Browse files
Files changed (1) hide show
  1. app_local.py +27 -7
app_local.py CHANGED
@@ -4,7 +4,7 @@ import random
4
  import torch
5
  import spaces
6
  from PIL import Image
7
- from diffusers import QwenImageEditPipeline
8
  from diffusers.utils import is_xformers_available
9
  import os
10
  import sys
@@ -211,10 +211,33 @@ def polish_prompt(original_prompt: str) -> str:
211
  rewritten_prompt = rewritten_prompt.split(': ', 1)[-1].strip()
212
 
213
  return rewritten_prompt[:200] if rewritten_prompt else original_prompt
214
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  # Load main image editing pipeline
216
  pipe = QwenImageEditPipeline.from_pretrained(
217
  LOC,
 
218
  torch_dtype=dtype
219
  ).to(device)
220
 
@@ -249,13 +272,10 @@ def infer(
249
  num_inference_steps=8,
250
  rewrite_prompt=True,
251
  num_images_per_prompt=1,
 
252
  ):
253
  """Image editing endpoint with optimized prompt handling"""
254
- # Clear cache at start
255
- if device == "cuda":
256
- torch.cuda.empty_cache()
257
- gc.collect()
258
-
259
  # Resize image to max 1024px on longest side
260
  def resize_image(pil_image, max_size=1024):
261
  """Resize image to maximum dimension of 1024px while maintaining aspect ratio"""
 
4
  import torch
5
  import spaces
6
  from PIL import Image
7
+ from diffusers import QwenImageEditPipeline, FlowMatchEulerDiscreteScheduler
8
  from diffusers.utils import is_xformers_available
9
  import os
10
  import sys
 
211
  rewritten_prompt = rewritten_prompt.split(': ', 1)[-1].strip()
212
 
213
  return rewritten_prompt[:200] if rewritten_prompt else original_prompt
214
+
215
+ # Scheduler configuration for Lightning
216
+ scheduler_config = {
217
+ "base_image_seq_len": 256,
218
+ "base_shift": math.log(3),
219
+ "invert_sigmas": False,
220
+ "max_image_seq_len": 8192,
221
+ "max_shift": math.log(3),
222
+ "num_train_timesteps": 1000,
223
+ "shift": 1.0,
224
+ "shift_terminal": None,
225
+ "stochastic_sampling": False,
226
+ "time_shift_type": "exponential",
227
+ "use_beta_sigmas": False,
228
+ "use_dynamic_shifting": True,
229
+ "use_exponential_sigmas": False,
230
+ "use_karras_sigmas": False,
231
+ }
232
+
233
+ # Initialize scheduler with Lightning config
234
+ scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config)
235
+
236
+
237
  # Load main image editing pipeline
238
  pipe = QwenImageEditPipeline.from_pretrained(
239
  LOC,
240
+ scheduler=scheduler,
241
  torch_dtype=dtype
242
  ).to(device)
243
 
 
272
  num_inference_steps=8,
273
  rewrite_prompt=True,
274
  num_images_per_prompt=1,
275
+ progress=gr.Progress(track_tqdm=True),
276
  ):
277
  """Image editing endpoint with optimized prompt handling"""
278
+
 
 
 
 
279
  # Resize image to max 1024px on longest side
280
  def resize_image(pil_image, max_size=1024):
281
  """Resize image to maximum dimension of 1024px while maintaining aspect ratio"""