Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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']
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
inpainting_mode = np.asarray(background).sum() != 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
print('Inpainting mode: ', inpainting_mode)
|
| 328 |
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 530 |
<h5 style="margin: 0;">powered by</h5>
|
| 531 |
-
<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://
|
| 537 |
-
<img src=
|
| 538 |
</a>
|
| 539 |
|
| 540 |
-
<a href='https://
|
| 541 |
-
<img src=
|
| 542 |
</a>
|
| 543 |
|
| 544 |
-
<a href='https://github.com/ironjr/
|
| 545 |
-
<img src='https://img.shields.io/github/stars/ironjr/
|
| 546 |
</a>
|
| 547 |
|
| 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 |
|
| 552 |
-
<a href='https://github.com/ironjr/
|
| 553 |
<img src='https://img.shields.io/badge/license-MIT-lightgrey'>
|
| 554 |
</a>
|
| 555 |
|
| 556 |
-
<a href='https://huggingface.co/
|
| 557 |
-
<img src='https://img.shields.io/badge/%F0%9F%A4%97%
|
| 558 |
</a>
|
| 559 |
|
| 560 |
-
<a href='https://huggingface.co/
|
| 561 |
-
<img src='https://img.shields.io/badge/%F0%9F%A4%97%
|
| 562 |
</a>
|
| 563 |
|
| 564 |
-
<a href='https://huggingface.co/spaces/ironjr/
|
| 565 |
-
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-
|
| 566 |
</a>
|
| 567 |
|
| 568 |
-
<a href='https://huggingface.co/spaces/ironjr/
|
| 569 |
-
<img src='https://img.shields.io/badge/%F0%9F%A4%97%20Demo-
|
| 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 |
|
| 553 |
+
<a href='https://arxiv.org/abs/2403.09055'>
|
| 554 |
+
<img src="https://img.shields.io/badge/arXiv-2403.09055-red">
|
| 555 |
</a>
|
| 556 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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>
|