prithivMLmods commited on
Commit
0737481
·
verified ·
1 Parent(s): e1750df

update app

Browse files
Files changed (1) hide show
  1. app.py +36 -7
app.py CHANGED
@@ -240,8 +240,32 @@ def infer(
240
  # Save RRD
241
  rrd_path = os.path.join(TMP_DIR, f"{run_id}.rrd")
242
  rec.save(rrd_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
 
244
- return rrd_path, seed
245
 
246
  except Exception as e:
247
  raise e
@@ -252,14 +276,14 @@ def infer(
252
  @spaces.GPU
253
  def infer_example(input_image, prompt, lora_adapter):
254
  if input_image is None:
255
- return None, 0
256
 
257
  input_pil = input_image.convert("RGB")
258
  guidance_scale = 1.0
259
  steps = 4
260
  # Call main infer but ignore progress for examples if needed
261
- result_rrd, seed = infer(input_pil, prompt, lora_adapter, 0, True, guidance_scale, steps)
262
- return result_rrd, seed
263
 
264
  css="""
265
  #col-container {
@@ -274,7 +298,7 @@ with gr.Blocks() as demo:
274
  gr.Markdown("# **Qwen-Image-Edit-2511-LoRAs-Fast**", elem_id="main-title")
275
  gr.Markdown("Perform diverse image edits using specialized [LoRA](https://huggingface.co/models?other=base_model:adapter:Qwen/Qwen-Image-Edit-2511) adapters for the [Qwen-Image-Edit](https://huggingface.co/Qwen/Qwen-Image-Edit-2511) model.")
276
 
277
- with gr.Row():
278
  with gr.Column():
279
  input_image = gr.Image(label="Upload Image", type="pil", height=290)
280
 
@@ -292,6 +316,8 @@ with gr.Blocks() as demo:
292
  label="Rerun Visualization",
293
  height=353
294
  )
 
 
295
 
296
  with gr.Row():
297
  lora_adapter = gr.Dropdown(
@@ -299,6 +325,9 @@ with gr.Blocks() as demo:
299
  choices=list(ADAPTER_SPECS.keys()),
300
  value="Photo-to-Anime"
301
  )
 
 
 
302
  with gr.Accordion("Advanced Settings", open=False, visible=False):
303
  seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
304
  randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
@@ -311,7 +340,7 @@ with gr.Blocks() as demo:
311
  ["examples/A.jpeg", "Rotate the camera 45 degrees to the right.", "Multiple-Angles"],
312
  ],
313
  inputs=[input_image, prompt, lora_adapter],
314
- outputs=[rerun_output, seed],
315
  fn=infer_example,
316
  cache_examples=False,
317
  label="Examples"
@@ -322,7 +351,7 @@ with gr.Blocks() as demo:
322
  run_button.click(
323
  fn=infer,
324
  inputs=[input_image, prompt, lora_adapter, seed, randomize_seed, guidance_scale, steps],
325
- outputs=[rerun_output, seed]
326
  )
327
 
328
  if __name__ == "__main__":
 
240
  # Save RRD
241
  rrd_path = os.path.join(TMP_DIR, f"{run_id}.rrd")
242
  rec.save(rrd_path)
243
+
244
+ # Save Image for Download
245
+ image_path = os.path.join(TMP_DIR, f"{run_id}.png")
246
+ result_image.save(image_path)
247
+
248
+ # Create HTML download bar
249
+ download_html = f'''
250
+ <a href="/file={image_path}" download="edited_image_{run_id}.png" target="_blank" style="
251
+ display: block;
252
+ width: 100%;
253
+ background-color: #FF4500;
254
+ color: white;
255
+ text-align: center;
256
+ padding: 10px 0;
257
+ margin-top: 10px;
258
+ border-radius: 8px;
259
+ text-decoration: none;
260
+ font-weight: 600;
261
+ font-family: 'Outfit', sans-serif;
262
+ transition: background-color 0.2s;
263
+ " onmouseover="this.style.backgroundColor='#E63E00'" onmouseout="this.style.backgroundColor='#FF4500'">
264
+ Download Generated Image
265
+ </a>
266
+ '''
267
 
268
+ return rrd_path, download_html, seed
269
 
270
  except Exception as e:
271
  raise e
 
276
  @spaces.GPU
277
  def infer_example(input_image, prompt, lora_adapter):
278
  if input_image is None:
279
+ return None, None, 0
280
 
281
  input_pil = input_image.convert("RGB")
282
  guidance_scale = 1.0
283
  steps = 4
284
  # Call main infer but ignore progress for examples if needed
285
+ result_rrd, download_html, seed = infer(input_pil, prompt, lora_adapter, 0, True, guidance_scale, steps)
286
+ return result_rrd, download_html, seed
287
 
288
  css="""
289
  #col-container {
 
298
  gr.Markdown("# **Qwen-Image-Edit-2511-LoRAs-Fast**", elem_id="main-title")
299
  gr.Markdown("Perform diverse image edits using specialized [LoRA](https://huggingface.co/models?other=base_model:adapter:Qwen/Qwen-Image-Edit-2511) adapters for the [Qwen-Image-Edit](https://huggingface.co/Qwen/Qwen-Image-Edit-2511) model.")
300
 
301
+ with gr.Row(equal_height=True):
302
  with gr.Column():
303
  input_image = gr.Image(label="Upload Image", type="pil", height=290)
304
 
 
316
  label="Rerun Visualization",
317
  height=353
318
  )
319
+ # HTML Download Bar
320
+ download_html = gr.HTML()
321
 
322
  with gr.Row():
323
  lora_adapter = gr.Dropdown(
 
325
  choices=list(ADAPTER_SPECS.keys()),
326
  value="Photo-to-Anime"
327
  )
328
+
329
+
330
+
331
  with gr.Accordion("Advanced Settings", open=False, visible=False):
332
  seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
333
  randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
 
340
  ["examples/A.jpeg", "Rotate the camera 45 degrees to the right.", "Multiple-Angles"],
341
  ],
342
  inputs=[input_image, prompt, lora_adapter],
343
+ outputs=[rerun_output, download_html, seed],
344
  fn=infer_example,
345
  cache_examples=False,
346
  label="Examples"
 
351
  run_button.click(
352
  fn=infer,
353
  inputs=[input_image, prompt, lora_adapter, seed, randomize_seed, guidance_scale, steps],
354
+ outputs=[rerun_output, download_html, seed]
355
  )
356
 
357
  if __name__ == "__main__":