cocktailpeanut 6Morpheus6 commited on
Commit
305f206
1 Parent(s): aab1f68

Image Download (#4)

Browse files

- Image Download (3c63bff61c6dd2f21051412cb98945e6af074801)


Co-authored-by: Morpheus <6Morpheus6@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -69,9 +69,10 @@ pipe = StableDiffusionXLInstantIDPipeline.from_pretrained(
69
  feature_extractor=None,
70
  )
71
  #pipe.cuda()
72
-
73
- num_inference_steps = 30
74
- guidance_scale = 5
 
75
 
76
  # LCM
77
  if os.environ.get("MODE") == "LCM":
@@ -311,13 +312,18 @@ def generate_image(
311
  generator=generator,
312
  ).images
313
 
 
 
 
 
 
314
  gc.collect()
315
  if device == 'mps':
316
  torch.mps.empty_cache()
317
  elif device == 'cuda':
318
  torch.cuda.empty_cache()
319
 
320
- return images[0], gr.update(visible=True)
321
 
322
 
323
  ### Description
@@ -363,8 +369,10 @@ tips = r"""
363
  """
364
 
365
  css = """
366
- .gradio-container {width: 85% !important}
 
367
  """
 
368
  with gr.Blocks(css=css) as demo:
369
  # description
370
  gr.Markdown(title)
@@ -392,7 +400,7 @@ with gr.Blocks(css=css) as demo:
392
 
393
  # strength
394
  identitynet_strength_ratio = gr.Slider(
395
- label="IdentityNet strength (for fedility)",
396
  minimum=0,
397
  maximum=1.5,
398
  step=0.05,
@@ -410,7 +418,7 @@ with gr.Blocks(css=css) as demo:
410
  negative_prompt = gr.Textbox(
411
  label="Negative Prompt",
412
  placeholder="low quality",
413
- value="(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, nudity,naked, bikini, skimpy, scanty, bare skin, lingerie, swimsuit, exposed, see-through, photo, anthropomorphic cat, monochrome, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
414
  )
415
  num_steps = gr.Slider(
416
  label="Number of sample steps",
@@ -438,6 +446,7 @@ with gr.Blocks(css=css) as demo:
438
 
439
  with gr.Column():
440
  output_image = gr.Image(label="Generated Image")
 
441
  usage_tips = gr.Markdown(label="Usage tips of InstantID", value=tips, visible=False)
442
 
443
  submit.click(
@@ -471,13 +480,13 @@ with gr.Blocks(css=css) as demo:
471
  guidance_scale,
472
  seed,
473
  ],
474
- outputs=[output_image, usage_tips],
475
  )
476
 
477
  gr.Examples(
478
  examples=get_example(),
479
  inputs=[face_file, prompt, style, negative_prompt],
480
- outputs=[output_image, usage_tips],
481
  fn=run_for_examples,
482
  )
483
 
 
69
  feature_extractor=None,
70
  )
71
  #pipe.cuda()
72
+ if os.environ.get("MODE") == "Default":
73
+ print("Default")
74
+ num_inference_steps = 30
75
+ guidance_scale = 5
76
 
77
  # LCM
78
  if os.environ.get("MODE") == "LCM":
 
312
  generator=generator,
313
  ).images
314
 
315
+ gradio_temp_dir = os.environ['GRADIO_TEMP_DIR']
316
+ temp_file_path = os.path.join(gradio_temp_dir, "image.png")
317
+ images[0].save(temp_file_path, format="PNG")
318
+ print(f"Image saved in: {temp_file_path}")
319
+
320
  gc.collect()
321
  if device == 'mps':
322
  torch.mps.empty_cache()
323
  elif device == 'cuda':
324
  torch.cuda.empty_cache()
325
 
326
+ return images[0], gr.update(visible=True), temp_file_path
327
 
328
 
329
  ### Description
 
369
  """
370
 
371
  css = """
372
+ .gradio-container { width: 90% !important }
373
+ #row-height { height: 65px !important }
374
  """
375
+
376
  with gr.Blocks(css=css) as demo:
377
  # description
378
  gr.Markdown(title)
 
400
 
401
  # strength
402
  identitynet_strength_ratio = gr.Slider(
403
+ label="IdentityNet strength (for fidelity)",
404
  minimum=0,
405
  maximum=1.5,
406
  step=0.05,
 
418
  negative_prompt = gr.Textbox(
419
  label="Negative Prompt",
420
  placeholder="low quality",
421
+ value="(lowres, low quality, worst quality:1.2), (text:1.2), (frame:1.2), watermark, deformed, ugly, deformed eyes, blur, blurry, noisy, out of focus, nudity, naked, skimpy, scanty, bare skin, exposed, monochrome, pet collar",
422
  )
423
  num_steps = gr.Slider(
424
  label="Number of sample steps",
 
446
 
447
  with gr.Column():
448
  output_image = gr.Image(label="Generated Image")
449
+ download_image = gr.File(label="Download Image", file_count="single", elem_id="row-height")
450
  usage_tips = gr.Markdown(label="Usage tips of InstantID", value=tips, visible=False)
451
 
452
  submit.click(
 
480
  guidance_scale,
481
  seed,
482
  ],
483
+ outputs=[output_image, usage_tips, download_image],
484
  )
485
 
486
  gr.Examples(
487
  examples=get_example(),
488
  inputs=[face_file, prompt, style, negative_prompt],
489
+ outputs=[output_image, usage_tips, download_image],
490
  fn=run_for_examples,
491
  )
492