Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -296,13 +296,27 @@ def run(state, drawpad):
|
|
296 |
seed_everything(state.seed if state.seed >=0 else np.random.randint(2147483647))
|
297 |
print('Generate!')
|
298 |
|
299 |
-
background = drawpad['background']
|
|
|
|
|
|
|
|
|
300 |
inpainting_mode = np.asarray(background).sum() != 0
|
|
|
|
|
|
|
|
|
|
|
301 |
print('Inpainting mode: ', inpainting_mode)
|
302 |
|
303 |
-
|
304 |
-
|
305 |
-
|
|
|
|
|
|
|
|
|
|
|
306 |
|
307 |
palette = torch.tensor([
|
308 |
tuple(int(s[i+1:i+3], 16) for i in (0, 2, 4))
|
@@ -514,7 +528,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
514 |
state.seed = opt.seed
|
515 |
return state
|
516 |
|
517 |
-
state = gr.State(value=_define_state)
|
518 |
|
519 |
|
520 |
### Demo user interface
|
@@ -523,43 +537,46 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
523 |
"""
|
524 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
525 |
<div>
|
526 |
-
<h1>🧠 Semantic
|
527 |
<h5 style="margin: 0;">powered by</h5>
|
528 |
-
<h3
|
529 |
<h5 style="margin: 0;">If you ❤️ our project, please visit our Github and give us a 🌟!</h5>
|
530 |
-
<h5 style="margin: 1px;">Check out our new <a href="https://huggingface.co/spaces/ironjr/SemanticPaletteXL">demo</a> in collaboration with Animagine XL 3.1 🤩!</h5>
|
531 |
</br>
|
532 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
533 |
-
<a href='https://
|
534 |
-
<img src=
|
535 |
</a>
|
536 |
|
537 |
-
<a href='https://
|
538 |
-
<img src=
|
539 |
</a>
|
540 |
|
541 |
-
<a href='https://github.com/ironjr/
|
542 |
-
<img src='https://img.shields.io/github/stars/ironjr/
|
543 |
</a>
|
544 |
|
545 |
<a href='https://twitter.com/_ironjr_'>
|
546 |
<img src='https://img.shields.io/twitter/url?label=_ironjr_&url=https%3A%2F%2Ftwitter.com%2F_ironjr_'>
|
547 |
</a>
|
548 |
|
549 |
-
<a href='https://github.com/ironjr/
|
550 |
<img src='https://img.shields.io/badge/license-MIT-lightgrey'>
|
551 |
</a>
|
552 |
|
553 |
-
<a href='https://huggingface.co/
|
554 |
-
<img src='https://img.shields.io/badge/%F0%9F%A4%97%
|
|
|
|
|
|
|
|
|
555 |
</a>
|
556 |
|
557 |
-
<a href='https://huggingface.co/spaces/ironjr/
|
558 |
-
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-
|
559 |
</a>
|
560 |
|
561 |
-
<a href='https://huggingface.co/spaces/ironjr/
|
562 |
-
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-
|
563 |
</a>
|
564 |
</div>
|
565 |
</div>
|
|
|
296 |
seed_everything(state.seed if state.seed >=0 else np.random.randint(2147483647))
|
297 |
print('Generate!')
|
298 |
|
299 |
+
background = drawpad['background']
|
300 |
+
if background is None:
|
301 |
+
background = Image.new(size=(opt.width, opt.height), mode='RGB', color=(255, 255, 255))
|
302 |
+
else:
|
303 |
+
background = background.convert('RGBA')
|
304 |
inpainting_mode = np.asarray(background).sum() != 0
|
305 |
+
if not inpainting_mode:
|
306 |
+
background = Image.new(size=(opt.width, opt.height), mode='RGB', color=(255, 255, 255))
|
307 |
+
background_prompt = "Simple white background"
|
308 |
+
else:
|
309 |
+
background_prompt = None
|
310 |
print('Inpainting mode: ', inpainting_mode)
|
311 |
|
312 |
+
if drawpad['composite'] is None:
|
313 |
+
user_input = np.zeros((opt.height, opt.width, 4))
|
314 |
+
foreground_mask = torch.zeros((1, 1, opt.height, opt.width))
|
315 |
+
user_input = torch.tensor(user_input[..., :-1]) # (H, W, 3)
|
316 |
+
else:
|
317 |
+
user_input = np.asarray(drawpad['composite']) # (H, W, 4)
|
318 |
+
foreground_mask = torch.tensor(user_input[..., -1])[None, None] # (1, 1, H, W)
|
319 |
+
user_input = torch.tensor(user_input[..., :-1]) # (H, W, 3)
|
320 |
|
321 |
palette = torch.tensor([
|
322 |
tuple(int(s[i+1:i+3], 16) for i in (0, 2, 4))
|
|
|
528 |
state.seed = opt.seed
|
529 |
return state
|
530 |
|
531 |
+
state = gr.State(value=_define_state())
|
532 |
|
533 |
|
534 |
### Demo user interface
|
|
|
537 |
"""
|
538 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
539 |
<div>
|
540 |
+
<h1>🧠 Semantic Draw Canvas 🎨</h1>
|
541 |
<h5 style="margin: 0;">powered by</h5>
|
542 |
+
<h3>SemanticDraw: Towards Real-Time Interactive Content Creation from Image Diffusion Models</h3>
|
543 |
<h5 style="margin: 0;">If you ❤️ our project, please visit our Github and give us a 🌟!</h5>
|
|
|
544 |
</br>
|
545 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
546 |
+
<a href='https://jaerinlee.com/research/semantic-draw'>
|
547 |
+
<img src='https://img.shields.io/badge/Project-Page-green' alt='Project Page'>
|
548 |
</a>
|
549 |
|
550 |
+
<a href='https://arxiv.org/abs/2403.09055'>
|
551 |
+
<img src="https://img.shields.io/badge/arXiv-2403.09055-red">
|
552 |
</a>
|
553 |
|
554 |
+
<a href='https://github.com/ironjr/semantic-draw'>
|
555 |
+
<img src='https://img.shields.io/github/stars/ironjr/semantic-draw?label=Github&color=blue'>
|
556 |
</a>
|
557 |
|
558 |
<a href='https://twitter.com/_ironjr_'>
|
559 |
<img src='https://img.shields.io/twitter/url?label=_ironjr_&url=https%3A%2F%2Ftwitter.com%2F_ironjr_'>
|
560 |
</a>
|
561 |
|
562 |
+
<a href='https://github.com/ironjr/semantic-draw/blob/main/LICENSE'>
|
563 |
<img src='https://img.shields.io/badge/license-MIT-lightgrey'>
|
564 |
</a>
|
565 |
|
566 |
+
<a href='https://huggingface.co/spaces/ironjr/semantic-draw'>
|
567 |
+
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-Stream-yellow'>
|
568 |
+
</a>
|
569 |
+
|
570 |
+
<a href='https://huggingface.co/spaces/ironjr/semantic-draw-canvas-sd15'>
|
571 |
+
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-CanvasSD1.5-yellow'>
|
572 |
</a>
|
573 |
|
574 |
+
<a href='https://huggingface.co/spaces/ironjr/semantic-draw-canvas-sdxl'>
|
575 |
+
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-CanvasSDXL-yellow'>
|
576 |
</a>
|
577 |
|
578 |
+
<a href='https://huggingface.co/spaces/ironjr/semantic-draw-canvas-sd3'>
|
579 |
+
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-CanvasSD3-yellow'>
|
580 |
</a>
|
581 |
</div>
|
582 |
</div>
|