ironjr commited on
Commit
3cd05c2
Β·
verified Β·
1 Parent(s): ff5d725

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -23
app.py CHANGED
@@ -322,13 +322,27 @@ def run(state, drawpad):
322
  seed_everything(state.seed if state.seed >=0 else np.random.randint(2147483647))
323
  print('Generate!')
324
 
325
- background = drawpad['background'].convert('RGBA')
 
 
 
 
326
  inpainting_mode = np.asarray(background).sum() != 0
 
 
 
 
 
327
  print('Inpainting mode: ', inpainting_mode)
328
 
329
- user_input = np.asarray(drawpad['layers'][0]) # (H, W, 4)
330
- foreground_mask = torch.tensor(user_input[..., -1])[None, None] # (1, 1, H, W)
331
- user_input = torch.tensor(user_input[..., :-1]) # (H, W, 3)
 
 
 
 
 
332
 
333
  palette = torch.tensor([
334
  tuple(int(s[i+1:i+3], 16) for i in (0, 2, 4))
@@ -517,7 +531,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
517
  state.seed = opt.seed
518
  return state
519
 
520
- state = gr.State(value=_define_state)
521
 
522
 
523
  ### Demo user interface
@@ -526,47 +540,46 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
526
  """
527
  <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
528
  <div>
529
- <h1>πŸ”₯🧠 Semantic Palette <b>X</b> Animagine XL 3.1 🎨πŸ”₯</h1>
530
  <h5 style="margin: 0;">powered by</h5>
531
- <h3 style="margin-bottom: 0;"><a href="https://github.com/ironjr/StreamMultiDiffusion">StreamMultiDiffusion: Real-Time Interactive Generation with Region-Based Semantic Control</a> &nbsp; <em>and</em></h3>
532
- <h3 style="margin-top: 0;"><a href="https://huggingface.co/cagliostrolab/animagine-xl-3.1">Animagine XL 3.1</a> by <a href="https://cagliostrolab.net/">Cagliostro Research Lab</a></h3>
533
  <h5 style="margin: 0;">If you ❀️ our project, please visit our Github and give us a 🌟!</h5>
534
  </br>
535
  <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
536
- <a href='https://arxiv.org/abs/2403.09055'>
537
- <img src="https://img.shields.io/badge/arXiv-2403.09055-red">
538
  </a>
539
  &nbsp;
540
- <a href='https://jaerinlee.com/research/StreamMultiDiffusion'>
541
- <img src='https://img.shields.io/badge/Project-Page-green' alt='Project Page'>
542
  </a>
543
  &nbsp;
544
- <a href='https://github.com/ironjr/StreamMultiDiffusion'>
545
- <img src='https://img.shields.io/github/stars/ironjr/StreamMultiDiffusion?label=Github&color=blue'>
546
  </a>
547
  &nbsp;
548
  <a href='https://twitter.com/_ironjr_'>
549
  <img src='https://img.shields.io/twitter/url?label=_ironjr_&url=https%3A%2F%2Ftwitter.com%2F_ironjr_'>
550
  </a>
551
  &nbsp;
552
- <a href='https://github.com/ironjr/StreamMultiDiffusion/blob/main/LICENSE'>
553
  <img src='https://img.shields.io/badge/license-MIT-lightgrey'>
554
  </a>
555
  &nbsp;
556
- <a href='https://huggingface.co/papers/2403.09055'>
557
- <img src='https://img.shields.io/badge/%F0%9F%A4%97%20Paper-StreamMultiDiffusion-yellow'>
558
  </a>
559
  &nbsp;
560
- <a href='https://huggingface.co/cagliostrolab/animagine-xl-3.1'>
561
- <img src='https://img.shields.io/badge/%F0%9F%A4%97%20Model-AnimagineXL3.1-yellow'>
562
  </a>
563
  &nbsp;
564
- <a href='https://huggingface.co/spaces/ironjr/SemanticPalette'>
565
- <img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-v1.5-yellow'>
566
  </a>
567
  &nbsp;
568
- <a href='https://huggingface.co/spaces/ironjr/StreamMultiDiffusion'>
569
- <img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-StreamMultiDiffusion-yellow'>
570
  </a>
571
  </div>
572
  </div>
 
322
  seed_everything(state.seed if state.seed >=0 else np.random.randint(2147483647))
323
  print('Generate!')
324
 
325
+ background = drawpad['background']
326
+ if background is None:
327
+ background = Image.new(size=(opt.width, opt.height), mode='RGB', color=(255, 255, 255))
328
+ else:
329
+ background = background.convert('RGBA')
330
  inpainting_mode = np.asarray(background).sum() != 0
331
+ if not inpainting_mode:
332
+ background = Image.new(size=(opt.width, opt.height), mode='RGB', color=(255, 255, 255))
333
+ background_prompt = "Simple white background"
334
+ else:
335
+ background_prompt = None
336
  print('Inpainting mode: ', inpainting_mode)
337
 
338
+ if drawpad['composite'] is None:
339
+ user_input = np.zeros((opt.height, opt.width, 4))
340
+ foreground_mask = torch.zeros((1, 1, opt.height, opt.width))
341
+ user_input = torch.tensor(user_input[..., :-1]) # (H, W, 3)
342
+ else:
343
+ user_input = np.asarray(drawpad['composite']) # (H, W, 4)
344
+ foreground_mask = torch.tensor(user_input[..., -1])[None, None] # (1, 1, H, W)
345
+ user_input = torch.tensor(user_input[..., :-1]) # (H, W, 3)
346
 
347
  palette = torch.tensor([
348
  tuple(int(s[i+1:i+3], 16) for i in (0, 2, 4))
 
531
  state.seed = opt.seed
532
  return state
533
 
534
+ state = gr.State(value=_define_state())
535
 
536
 
537
  ### Demo user interface
 
540
  """
541
  <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
542
  <div>
543
+ <h1>πŸ”₯🧠 Semantic Draw Canvas <b>X</b> Animagine XL 3.1 🎨πŸ”₯</h1>
544
  <h5 style="margin: 0;">powered by</h5>
545
+ <h3>SemanticDraw: Towards Real-Time Interactive Content Creation from Image Diffusion Models</h3>
 
546
  <h5 style="margin: 0;">If you ❀️ our project, please visit our Github and give us a 🌟!</h5>
547
  </br>
548
  <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
549
+ <a href='https://jaerinlee.com/research/semantic-draw'>
550
+ <img src='https://img.shields.io/badge/Project-Page-green' alt='Project Page'>
551
  </a>
552
  &nbsp;
553
+ <a href='https://arxiv.org/abs/2403.09055'>
554
+ <img src="https://img.shields.io/badge/arXiv-2403.09055-red">
555
  </a>
556
  &nbsp;
557
+ <a href='https://github.com/ironjr/semantic-draw'>
558
+ <img src='https://img.shields.io/github/stars/ironjr/semantic-draw?label=Github&color=blue'>
559
  </a>
560
  &nbsp;
561
  <a href='https://twitter.com/_ironjr_'>
562
  <img src='https://img.shields.io/twitter/url?label=_ironjr_&url=https%3A%2F%2Ftwitter.com%2F_ironjr_'>
563
  </a>
564
  &nbsp;
565
+ <a href='https://github.com/ironjr/semantic-draw/blob/main/LICENSE'>
566
  <img src='https://img.shields.io/badge/license-MIT-lightgrey'>
567
  </a>
568
  &nbsp;
569
+ <a href='https://huggingface.co/spaces/ironjr/semantic-draw'>
570
+ <img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-Stream-yellow'>
571
  </a>
572
  &nbsp;
573
+ <a href='https://huggingface.co/spaces/ironjr/semantic-draw-canvas-sd15'>
574
+ <img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-CanvasSD1.5-yellow'>
575
  </a>
576
  &nbsp;
577
+ <a href='https://huggingface.co/spaces/ironjr/semantic-draw-canvas-sdxl'>
578
+ <img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-CanvasSDXL-yellow'>
579
  </a>
580
  &nbsp;
581
+ <a href='https://huggingface.co/spaces/ironjr/semantic-draw-canvas-sd3'>
582
+ <img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-CanvasSD3-yellow'>
583
  </a>
584
  </div>
585
  </div>