Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -313,13 +313,27 @@ def run(state, drawpad):
|
|
313 |
seed_everything(state.seed if state.seed >=0 else np.random.randint(2147483647))
|
314 |
print('Generate!')
|
315 |
|
316 |
-
background = drawpad['background']
|
|
|
|
|
|
|
|
|
317 |
inpainting_mode = np.asarray(background).sum() != 0
|
|
|
|
|
|
|
|
|
|
|
318 |
print('Inpainting mode: ', inpainting_mode)
|
319 |
|
320 |
-
|
321 |
-
|
322 |
-
|
|
|
|
|
|
|
|
|
|
|
323 |
|
324 |
palette = torch.tensor([
|
325 |
tuple(int(s[i+1:i+3], 16) for i in (0, 2, 4))
|
@@ -603,7 +617,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
603 |
state.seed = opt.seed
|
604 |
return state
|
605 |
|
606 |
-
state = gr.State(value=_define_state)
|
607 |
|
608 |
|
609 |
### Demo user interface
|
@@ -612,13 +626,13 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
612 |
"""
|
613 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
614 |
<div>
|
615 |
-
<h1>🧠 Semantic
|
616 |
<h5 style="margin: 0;">powered by</h5>
|
617 |
-
<h3>
|
618 |
<h5 style="margin: 0;">If you ❤️ our project, please visit our Github and give us a 🌟!</h5>
|
619 |
</br>
|
620 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
621 |
-
<a href='https://jaerinlee.com/research/
|
622 |
<img src='https://img.shields.io/badge/Project-Page-green' alt='Project Page'>
|
623 |
</a>
|
624 |
|
@@ -626,32 +640,32 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
626 |
<img src="https://img.shields.io/badge/arXiv-2403.09055-red">
|
627 |
</a>
|
628 |
|
629 |
-
<a href='https://github.com/ironjr/
|
630 |
-
<img src='https://img.shields.io/github/stars/ironjr/
|
631 |
</a>
|
632 |
|
633 |
<a href='https://twitter.com/_ironjr_'>
|
634 |
<img src='https://img.shields.io/twitter/url?label=_ironjr_&url=https%3A%2F%2Ftwitter.com%2F_ironjr_'>
|
635 |
</a>
|
636 |
|
637 |
-
<a href='https://github.com/ironjr/
|
638 |
<img src='https://img.shields.io/badge/license-MIT-lightgrey'>
|
639 |
</a>
|
640 |
|
641 |
-
<a href='https://huggingface.co/spaces/ironjr/
|
642 |
-
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-
|
643 |
</a>
|
644 |
|
645 |
-
<a href='https://huggingface.co/spaces/ironjr/
|
646 |
-
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-
|
647 |
</a>
|
648 |
|
649 |
-
<a href='https://huggingface.co/spaces/ironjr/
|
650 |
-
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-
|
651 |
</a>
|
652 |
|
653 |
-
<a href='https://huggingface.co/spaces/ironjr/
|
654 |
-
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-
|
655 |
</a>
|
656 |
</div>
|
657 |
</div>
|
@@ -787,11 +801,11 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
787 |
</div>
|
788 |
<div style="display: inline-block; margin-top: 10px">
|
789 |
<div class="gallery">
|
790 |
-
<a href="https://huggingface.co/spaces/ironjr/
|
791 |
-
<img alt="AnimagineXL3.1 Demo" src="https://github.com/ironjr/
|
792 |
</a>
|
793 |
-
<a href="https://huggingface.co/spaces/ironjr/
|
794 |
-
<img alt="
|
795 |
</a>
|
796 |
</div>
|
797 |
</div>
|
|
|
313 |
seed_everything(state.seed if state.seed >=0 else np.random.randint(2147483647))
|
314 |
print('Generate!')
|
315 |
|
316 |
+
background = drawpad['background']
|
317 |
+
if background is None:
|
318 |
+
background = Image.new(size=(opt.width, opt.height), mode='RGB', color=(255, 255, 255))
|
319 |
+
else:
|
320 |
+
background = background.convert('RGBA')
|
321 |
inpainting_mode = np.asarray(background).sum() != 0
|
322 |
+
if not inpainting_mode:
|
323 |
+
background = Image.new(size=(opt.width, opt.height), mode='RGB', color=(255, 255, 255))
|
324 |
+
background_prompt = "Simple white background"
|
325 |
+
else:
|
326 |
+
background_prompt = None
|
327 |
print('Inpainting mode: ', inpainting_mode)
|
328 |
|
329 |
+
if drawpad['composite'] is None:
|
330 |
+
user_input = np.zeros((opt.height, opt.width, 4))
|
331 |
+
foreground_mask = torch.zeros((1, 1, opt.height, opt.width))
|
332 |
+
user_input = torch.tensor(user_input[..., :-1]) # (H, W, 3)
|
333 |
+
else:
|
334 |
+
user_input = np.asarray(drawpad['composite']) # (H, W, 4)
|
335 |
+
foreground_mask = torch.tensor(user_input[..., -1])[None, None] # (1, 1, H, W)
|
336 |
+
user_input = torch.tensor(user_input[..., :-1]) # (H, W, 3)
|
337 |
|
338 |
palette = torch.tensor([
|
339 |
tuple(int(s[i+1:i+3], 16) for i in (0, 2, 4))
|
|
|
617 |
state.seed = opt.seed
|
618 |
return state
|
619 |
|
620 |
+
state = gr.State(value=_define_state())
|
621 |
|
622 |
|
623 |
### Demo user interface
|
|
|
626 |
"""
|
627 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
628 |
<div>
|
629 |
+
<h1>🧠 Semantic Draw Canvas with <font class="rainbow rainbow_text_animated">Stable Diffusion 3</font> 🎨</h1>
|
630 |
<h5 style="margin: 0;">powered by</h5>
|
631 |
+
<h3>SemanticDraw: Towards Real-Time Interactive Content Creation from Image Diffusion Models</h3>
|
632 |
<h5 style="margin: 0;">If you ❤️ our project, please visit our Github and give us a 🌟!</h5>
|
633 |
</br>
|
634 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
635 |
+
<a href='https://jaerinlee.com/research/semantic-draw'>
|
636 |
<img src='https://img.shields.io/badge/Project-Page-green' alt='Project Page'>
|
637 |
</a>
|
638 |
|
|
|
640 |
<img src="https://img.shields.io/badge/arXiv-2403.09055-red">
|
641 |
</a>
|
642 |
|
643 |
+
<a href='https://github.com/ironjr/semantic-draw'>
|
644 |
+
<img src='https://img.shields.io/github/stars/ironjr/semantic-draw?label=Github&color=blue'>
|
645 |
</a>
|
646 |
|
647 |
<a href='https://twitter.com/_ironjr_'>
|
648 |
<img src='https://img.shields.io/twitter/url?label=_ironjr_&url=https%3A%2F%2Ftwitter.com%2F_ironjr_'>
|
649 |
</a>
|
650 |
|
651 |
+
<a href='https://github.com/ironjr/semantic-draw/blob/main/LICENSE'>
|
652 |
<img src='https://img.shields.io/badge/license-MIT-lightgrey'>
|
653 |
</a>
|
654 |
|
655 |
+
<a href='https://huggingface.co/spaces/ironjr/semantic-draw'>
|
656 |
+
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-semantic-draw-yellow'>
|
657 |
</a>
|
658 |
|
659 |
+
<a href='https://huggingface.co/spaces/ironjr/semantic-draw-canvas-sd15'>
|
660 |
+
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-CanvasSD1.5-yellow'>
|
661 |
</a>
|
662 |
|
663 |
+
<a href='https://huggingface.co/spaces/ironjr/semantic-draw-canvas-sdxl'>
|
664 |
+
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-CanvasSDXL-yellow'>
|
665 |
</a>
|
666 |
|
667 |
+
<a href='https://huggingface.co/spaces/ironjr/semantic-draw-canvas-sd3'>
|
668 |
+
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-CanvasSD3-yellow'>
|
669 |
</a>
|
670 |
</div>
|
671 |
</div>
|
|
|
801 |
</div>
|
802 |
<div style="display: inline-block; margin-top: 10px">
|
803 |
<div class="gallery">
|
804 |
+
<a href="https://huggingface.co/spaces/ironjr/semantic-draw-canvas-sdxl" target="_blank">
|
805 |
+
<img alt="AnimagineXL3.1 Demo" src="https://github.com/ironjr/semantic-draw/blob/main/demo/canvas_sd3/examples/icons/sdxl.webp?raw=true">
|
806 |
</a>
|
807 |
+
<a href="https://huggingface.co/spaces/ironjr/semantic-draw" target="_blank">
|
808 |
+
<img alt="SemanticDraw Demo" src="https://github.com/ironjr/semantic-draw/blob/main/demo/canvas_sd3/examples/icons/smd.gif?raw=true">
|
809 |
</a>
|
810 |
</div>
|
811 |
</div>
|