linoyts HF Staff commited on
Commit
0dca548
·
verified ·
1 Parent(s): 97e7d5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -22
app.py CHANGED
@@ -8,7 +8,7 @@ import math
8
  from diffusers import FlowMatchEulerDiscreteScheduler, QwenImageEditPlusPipeline
9
  from huggingface_hub import hf_hub_download
10
  from safetensors.torch import load_file
11
- from briarmbg import BriaRMBG # ✅ background remover
12
  import os
13
  import tempfile
14
 
@@ -94,7 +94,7 @@ def remove_background(image: Image.Image) -> Image.Image:
94
  # --- Inference ---
95
  @spaces.GPU
96
  def infer(
97
- gallery_images, # ✅ multiple images
98
  image_background,
99
  prompt="",
100
  seed=42,
@@ -113,11 +113,11 @@ def infer(
113
  if gallery_images:
114
  for gimg in gallery_images:
115
  pil_img = gimg[0] if isinstance(gimg, list) else gimg
116
- processed_subjects.append(remove_background(pil_img)) # ✅ remove bg
117
 
118
  all_inputs = processed_subjects
119
  if image_background is not None:
120
- all_inputs.append(image_background) # ✅ background stays as is
121
 
122
  if not all_inputs:
123
  raise gr.Error("Please upload at least one image or a background image.")
@@ -141,13 +141,8 @@ css = '''#col-container { max-width: 900px; margin: 0 auto; }
141
 
142
  with gr.Blocks(theme=gr.themes.Citrus(), css=css) as demo:
143
  with gr.Column(elem_id="col-container"):
144
- gr.Markdown("## 🧩 Qwen Image Edit — Fusion + Multi-image Input with Background Removal")
145
- gr.Markdown("""
146
- This version supports **multiple subject images** (auto background removal)
147
- and one **background image** (kept intact).
148
- LoRAs: [Qwen Lightning](https://huggingface.co/lightx2v/Qwen-Image-Lightning) ⚡ + [Qwen Fusion](https://huggingface.co/dx8152/Qwen-Image-Edit-2509-Fusion) 🧠
149
- """)
150
-
151
  with gr.Row():
152
  with gr.Column():
153
  gallery = gr.Gallery(
@@ -169,17 +164,17 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=css) as demo:
169
  with gr.Column():
170
  result = gr.ImageSlider(label="Output Image", interactive=False)
171
 
172
- gr.Examples(
173
- examples=[
174
- [["fusion_car.png", "fusion_shoes.png"], "fusion_bg.png", "put the car and shoes in the background"],
175
- [["wednesday_product.png"], "simple_room.png", "put the product in her hand"]
176
- ],
177
- inputs=[gallery, image_background, prompt],
178
- outputs=[result, seed],
179
- fn=infer,
180
- cache_examples="lazy",
181
- elem_id="examples"
182
- )
183
 
184
  inputs = [gallery, image_background, prompt, seed, randomize_seed, true_guidance_scale, num_inference_steps, height, width]
185
  outputs = [result, seed]
 
8
  from diffusers import FlowMatchEulerDiscreteScheduler, QwenImageEditPlusPipeline
9
  from huggingface_hub import hf_hub_download
10
  from safetensors.torch import load_file
11
+ from briarmbg import BriaRMBG
12
  import os
13
  import tempfile
14
 
 
94
  # --- Inference ---
95
  @spaces.GPU
96
  def infer(
97
+ gallery_images,
98
  image_background,
99
  prompt="",
100
  seed=42,
 
113
  if gallery_images:
114
  for gimg in gallery_images:
115
  pil_img = gimg[0] if isinstance(gimg, list) else gimg
116
+ processed_subjects.append(remove_background(pil_img))
117
 
118
  all_inputs = processed_subjects
119
  if image_background is not None:
120
+ all_inputs.append(image_background)
121
 
122
  if not all_inputs:
123
  raise gr.Error("Please upload at least one image or a background image.")
 
141
 
142
  with gr.Blocks(theme=gr.themes.Citrus(), css=css) as demo:
143
  with gr.Column(elem_id="col-container"):
144
+ gr.Markdown("## Qwen Image Edit — Fusion")
145
+ gr.Markdown(""" Qwen Image Edit 2509 ✨ Using [dx8152's Qwen-Image-Edit-2509 Fusion LoRA](https://huggingface.co/dx8152/Qwen-Image-Edit-2509-Fusion) and [lightx2v Qwen-Image-Lightning LoRA]() for 4-step inference 💨 """ )
 
 
 
 
 
146
  with gr.Row():
147
  with gr.Column():
148
  gallery = gr.Gallery(
 
164
  with gr.Column():
165
  result = gr.ImageSlider(label="Output Image", interactive=False)
166
 
167
+ # gr.Examples(
168
+ # examples=[
169
+ # [["fusion_car.png", "fusion_shoes.png"], "fusion_bg.png", "put the car and shoes in the background"],
170
+ # [["wednesday_product.png"], "simple_room.png", "put the product in her hand"]
171
+ # ],
172
+ # inputs=[gallery, image_background, prompt],
173
+ # outputs=[result, seed],
174
+ # fn=infer,
175
+ # cache_examples="lazy",
176
+ # elem_id="examples"
177
+ # )
178
 
179
  inputs = [gallery, image_background, prompt, seed, randomize_seed, true_guidance_scale, num_inference_steps, height, width]
180
  outputs = [result, seed]