HAL1993 commited on
Commit
91a8826
·
verified ·
1 Parent(s): b2507f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -50
app.py CHANGED
@@ -86,7 +86,7 @@ QUALITY_PROMPT = ", high quality, detailed, vibrant, professional lighting"
86
  # --- Main Inference Function ---
87
  @spaces.GPU(duration=40)
88
  def infer(
89
- images,
90
  prompt,
91
  progress=gr.Progress(track_tqdm=True),
92
  ):
@@ -107,19 +107,19 @@ def infer(
107
  # Set up the generator for reproducibility
108
  generator = torch.Generator(device=device).manual_seed(seed)
109
 
110
- # Load input images into PIL Images
111
- pil_images = []
112
- if images is not None:
113
- for item in images:
114
- try:
115
- if isinstance(item[0], Image.Image):
116
- pil_images.append(item[0].convert("RGB"))
117
- elif isinstance(item[0], str):
118
- pil_images.append(Image.open(item[0]).convert("RGB"))
119
- elif hasattr(item, "name"):
120
- pil_images.append(Image.open(item.name).convert("RGB"))
121
- except Exception:
122
- continue
123
 
124
  if height == 256 and width == 256:
125
  height, width = None, None
@@ -128,8 +128,8 @@ def infer(
128
  print(f"Seed: {seed}, Steps: {num_inference_steps}, Guidance: {true_guidance_scale}, Size: {width}x{height}")
129
 
130
  # Generate the image
131
- image = pipe(
132
- image=pil_images if len(pil_images) > 0 else None,
133
  prompt=prompt_final,
134
  height=height,
135
  width=width,
@@ -140,7 +140,7 @@ def infer(
140
  num_images_per_prompt=num_images_per_prompt,
141
  ).images
142
 
143
- return image
144
 
145
  # --- Gradio User Interface ---
146
  def create_demo():
@@ -168,7 +168,6 @@ def create_demo():
168
  }
169
  #general_items {
170
  width: 100%;
171
- max-width: 100%;
172
  margin: 2rem 0;
173
  display: flex;
174
  flex-direction: column;
@@ -181,7 +180,6 @@ def create_demo():
181
  padding: 1rem;
182
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.2);
183
  width: 100%;
184
- max-width: 100%;
185
  box-sizing: border-box;
186
  }
187
  h1 {
@@ -204,16 +202,16 @@ def create_demo():
204
  border: none;
205
  margin: 0.75rem 0;
206
  width: 100%;
207
- max-width: 100%;
208
  }
209
- .gr-gallery {
 
210
  width: 100%;
211
- max-width: 100%;
212
  border: 1px solid #FFFFFF;
213
  border-radius: 4px;
214
  box-sizing: border-box;
215
  }
216
- .gr-gallery img {
217
  width: 100%;
218
  height: auto;
219
  box-sizing: border-box;
@@ -225,7 +223,6 @@ def create_demo():
225
  border-radius: 4px;
226
  padding: 0.5rem;
227
  width: 100%;
228
- max-width: 100%;
229
  box-sizing: border-box;
230
  }
231
  input:hover, textarea:hover {
@@ -243,7 +240,6 @@ def create_demo():
243
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
244
  transition: box-shadow 0.3s, transform 0.3s;
245
  width: 100%;
246
- max-width: 100%;
247
  min-height: 48px;
248
  cursor: pointer;
249
  }
@@ -251,21 +247,7 @@ def create_demo():
251
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.5);
252
  transform: scale(1.05);
253
  }
254
- button[aria-label="Download"] {
255
- transform: scale(3);
256
- transform-origin: top right;
257
- background: #000000 !important;
258
- color: #FFFFFF !important;
259
- border: 1px solid #FFFFFF !important;
260
- border-radius: 4px;
261
- padding: 0.4rem !important;
262
- margin: 0.5rem !important;
263
- box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
264
- transition: box-shadow 0.3s;
265
- }
266
- button[aria-label="Download"]:hover {
267
- box-shadow: 0 0 12px rgba(255, 255, 255, 0.5);
268
- }
269
  button[aria-label="Fullscreen"], button[aria-label="Fullscreen"]:hover,
270
  button[aria-label="Share"], button[aria-label="Share"]:hover {
271
  display: none !important;
@@ -295,18 +277,21 @@ def create_demo():
295
  gr.Markdown("# Qwen Image Editor")
296
  gr.Markdown("Edit your images with precise instructions", elem_id="subtitle")
297
  with gr.Column(elem_id="input_column"):
298
- input_images = gr.Gallery(
299
- label="Input Images",
300
- show_label=True,
301
  type="pil",
302
  interactive=True,
303
- elem_classes=["gradio-component", "gr-gallery"]
 
 
304
  )
305
- result = gr.Gallery(
306
- label="Result",
307
- show_label=True,
308
  type="pil",
309
- elem_classes=["gradio-component", "gr-gallery"]
 
 
 
310
  )
311
  prompt = gr.Textbox(
312
  label="Prompt",
@@ -323,8 +308,8 @@ def create_demo():
323
  gr.on(
324
  triggers=[run_button.click, prompt.submit],
325
  fn=infer,
326
- inputs=[input_images, prompt],
327
- outputs=[result],
328
  )
329
 
330
  return demo
 
86
  # --- Main Inference Function ---
87
  @spaces.GPU(duration=40)
88
  def infer(
89
+ image,
90
  prompt,
91
  progress=gr.Progress(track_tqdm=True),
92
  ):
 
107
  # Set up the generator for reproducibility
108
  generator = torch.Generator(device=device).manual_seed(seed)
109
 
110
+ # Load input image into PIL Image
111
+ pil_image = None
112
+ if image is not None:
113
+ try:
114
+ if isinstance(image, Image.Image):
115
+ pil_image = image.convert("RGB")
116
+ elif isinstance(image, str):
117
+ pil_image = Image.open(image).convert("RGB")
118
+ elif hasattr(image, "name"):
119
+ pil_image = Image.open(image.name).convert("RGB")
120
+ except Exception as e:
121
+ print(f"Error loading image: {e}")
122
+ raise gr.Error("Failed to load input image.")
123
 
124
  if height == 256 and width == 256:
125
  height, width = None, None
 
128
  print(f"Seed: {seed}, Steps: {num_inference_steps}, Guidance: {true_guidance_scale}, Size: {width}x{height}")
129
 
130
  # Generate the image
131
+ output = pipe(
132
+ image=[pil_image] if pil_image is not None else None,
133
  prompt=prompt_final,
134
  height=height,
135
  width=width,
 
140
  num_images_per_prompt=num_images_per_prompt,
141
  ).images
142
 
143
+ return output[0] if output else None
144
 
145
  # --- Gradio User Interface ---
146
  def create_demo():
 
168
  }
169
  #general_items {
170
  width: 100%;
 
171
  margin: 2rem 0;
172
  display: flex;
173
  flex-direction: column;
 
180
  padding: 1rem;
181
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.2);
182
  width: 100%;
 
183
  box-sizing: border-box;
184
  }
185
  h1 {
 
202
  border: none;
203
  margin: 0.75rem 0;
204
  width: 100%;
 
205
  }
206
+ .image-container {
207
+ aspect-ratio: 1/1;
208
  width: 100%;
209
+ height: auto;
210
  border: 1px solid #FFFFFF;
211
  border-radius: 4px;
212
  box-sizing: border-box;
213
  }
214
+ .image-container img {
215
  width: 100%;
216
  height: auto;
217
  box-sizing: border-box;
 
223
  border-radius: 4px;
224
  padding: 0.5rem;
225
  width: 100%;
 
226
  box-sizing: border-box;
227
  }
228
  input:hover, textarea:hover {
 
240
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
241
  transition: box-shadow 0.3s, transform 0.3s;
242
  width: 100%;
 
243
  min-height: 48px;
244
  cursor: pointer;
245
  }
 
247
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.5);
248
  transform: scale(1.05);
249
  }
250
+ button[aria-label="Download"], button[aria-label="Download"]:hover,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  button[aria-label="Fullscreen"], button[aria-label="Fullscreen"]:hover,
252
  button[aria-label="Share"], button[aria-label="Share"]:hover {
253
  display: none !important;
 
277
  gr.Markdown("# Qwen Image Editor")
278
  gr.Markdown("Edit your images with precise instructions", elem_id="subtitle")
279
  with gr.Column(elem_id="input_column"):
280
+ input_image = gr.Image(
281
+ label="Input Image",
 
282
  type="pil",
283
  interactive=True,
284
+ show_download_button=False,
285
+ show_share_button=False,
286
+ elem_classes=["gradio-component", "image-container"]
287
  )
288
+ result_image = gr.Image(
289
+ label="Result Image",
 
290
  type="pil",
291
+ interactive=False,
292
+ show_download_button=False,
293
+ show_share_button=False,
294
+ elem_classes=["gradio-component", "image-container"]
295
  )
296
  prompt = gr.Textbox(
297
  label="Prompt",
 
308
  gr.on(
309
  triggers=[run_button.click, prompt.submit],
310
  fn=infer,
311
+ inputs=[input_image, prompt],
312
+ outputs=[result_image],
313
  )
314
 
315
  return demo