Spaces:
Paused
Paused
ZYM
commited on
Commit
•
ebadb3a
1
Parent(s):
1e50ca9
cfg+preview
Browse files- app.py +19 -5
- assets/previews/image1.webp +0 -0
- assets/previews/image2.webp +0 -0
- assets/previews/image3.webp +0 -0
- assets/previews/image4.webp +0 -0
app.py
CHANGED
@@ -346,8 +346,8 @@ def process_box():
|
|
346 |
return [gr.update(visible=True), *visibilities]
|
347 |
|
348 |
@torch.inference_mode()
|
349 |
-
@spaces.GPU(enable_queue=True)
|
350 |
-
def generate_image(bg_prompt, bg_class, bg_tags, seed, *conditions):
|
351 |
|
352 |
stack_cp = deepcopy(stack)
|
353 |
print(f"conditions: {conditions}")
|
@@ -408,6 +408,7 @@ def generate_image(bg_prompt, bg_class, bg_tags, seed, *conditions):
|
|
408 |
texts=prompts,
|
409 |
bboxes=bboxes,
|
410 |
num_inference_steps=50,
|
|
|
411 |
generator=generator,
|
412 |
text_attn_mask=None,
|
413 |
).images[0]
|
@@ -416,9 +417,10 @@ def generate_image(bg_prompt, bg_class, bg_tags, seed, *conditions):
|
|
416 |
|
417 |
return image
|
418 |
|
419 |
-
def process_example(bg_prompt, bg_class, bg_tags, color_str, style_str, text_str, box_str, seed):
|
420 |
global stack
|
421 |
global state
|
|
|
422 |
|
423 |
colors = color_str.split(",")
|
424 |
styles = style_str.split(",")
|
@@ -538,6 +540,7 @@ def main():
|
|
538 |
))
|
539 |
|
540 |
seed_ = gr.Slider(label="Seed", minimum=0, maximum=2147483647, value=42, step=1)
|
|
|
541 |
button_generate = gr.Button("(2) I've finished my texts, colors and styles, generate!", elem_id="main_button", interactive=True, variant='primary')
|
542 |
|
543 |
button_layout.click(process_box, inputs=[], outputs=[post_box, *color_row])
|
@@ -545,17 +548,19 @@ def main():
|
|
545 |
with gr.Column():
|
546 |
output_image = gr.Image(label="Output Image", interactive=False)
|
547 |
|
548 |
-
button_generate.click(generate_image, inputs=[bg_prompt, bg_class, bg_tags, seed_, *(prompts + colors + styles)], outputs=[output_image], queue=True)
|
549 |
|
550 |
# examples
|
551 |
color_str = gr.Textbox(label="Color list", value="", visible=False)
|
552 |
style_str = gr.Textbox(label="Font type list", value="", visible=False)
|
553 |
box_str = gr.Textbox(label="Bbox list", value="", visible=False)
|
554 |
text_str = gr.Textbox(label="Text list", value="", visible=False)
|
|
|
555 |
|
556 |
gr.Examples(
|
557 |
examples=[
|
558 |
[
|
|
|
559 |
'The image features a small bunny rabbit sitting in a basket filled with various flowers. The basket is placed on a yellow background, creating a vibrant and cheerful scene. The flowers surrounding the rabbit come in different sizes and colors, adding to the overall visual appeal of the image. The rabbit appears to be the main focus of the scene, and its presence among the flowers creates a sense of harmony and balance.',
|
560 |
'Facebook Post',
|
561 |
'green, yellow, minimalist, easter day, happy easter day, easter, happy easter, decoration, happy, egg, spring, selebration, poster, illustration, greeting, season, design, colorful, cute, template',
|
@@ -564,8 +569,10 @@ def main():
|
|
564 |
'MAY ALLYOUR PRAYERS BE ANSWERED**********HAVE A HAPPY**********Easter Day',
|
565 |
'[0.08267477203647416, 0.5355623100303951, 0.42857142857142855, 0.07477203647416414]; [0.08389057750759879, 0.1951367781155015, 0.38054711246200607, 0.03768996960486322]; [0.07537993920972644, 0.2601823708206687, 0.49544072948328266, 0.14650455927051673]',
|
566 |
1,
|
|
|
567 |
],
|
568 |
[
|
|
|
569 |
'The image features a large gray elephant sitting in a field of flowers, holding a smaller elephant in its arms. The scene is quite serene and picturesque, with the two elephants being the main focus of the image. The field is filled with various flowers, creating a beautiful and vibrant backdrop for the elephants.',
|
570 |
'Cards and invitations',
|
571 |
'Light green, orange, Illustration, watercolor, playful, Baby shower invitation, baby boy shower invitation, baby boy, welcoming baby boy, koala baby shower invitation, baby shower invitation for baby shower, baby boy invitation, background, playful baby shower card, baby shower, card, newborn, born, Baby Shirt Baby Shower Invitation',
|
@@ -574,8 +581,10 @@ def main():
|
|
574 |
"RSVP to +123-456-7890**********Olivia Wilson**********Baby Shower**********Please Join Us For a**********In Honoring**********23 November, 2021 | 03:00 PM Fauget Hotels",
|
575 |
'[0.07112462006079028, 0.6462006079027356, 0.3373860182370821, 0.026747720364741642]; [0.07051671732522796, 0.38662613981762917, 0.37264437689969604, 0.059574468085106386]; [0.07234042553191489, 0.15623100303951368, 0.6547112462006079, 0.12401215805471125]; [0.0662613981762918, 0.06747720364741641, 0.3981762917933131, 0.035866261398176294]; [0.07051671732522796, 0.31550151975683893, 0.22006079027355624, 0.03951367781155015]; [0.06990881458966565, 0.48328267477203646, 0.39878419452887537, 0.1094224924012158]',
|
576 |
1,
|
|
|
577 |
],
|
578 |
[
|
|
|
579 |
'The image features a white background with a variety of colorful flowers and decorations. There are several pink flowers scattered throughout the scene, with some positioned closer to the top and others near the bottom. A blue flower can also be seen in the middle of the image. The overall composition creates a visually appealing and vibrant display.',
|
580 |
'Instagram Posts',
|
581 |
'grey, navy, purple, pink, teal, colorful, illustration, happy, celebration, post, party, year, new, event, celebrate, happy new year, new year, countdown, sparkle, firework',
|
@@ -583,9 +592,11 @@ def main():
|
|
583 |
'Caveat-Regular, Gagalin-Regular, Quicksand-Light, Quicksand-Light',
|
584 |
'Happy New Year**********2024**********All THE BEST**********A fresh start to start a change for the better.',
|
585 |
'[0.2936170212765957, 0.2887537993920973, 0.40303951367781155, 0.07173252279635259]; [0.24984802431610942, 0.3951367781155015, 0.46200607902735563, 0.17203647416413373]; [0.3951367781155015, 0.1094224924012158, 0.2109422492401216, 0.02796352583586626]; [0.20911854103343466, 0.6127659574468085, 0.5586626139817629, 0.08085106382978724]',
|
586 |
-
|
|
|
587 |
],
|
588 |
[
|
|
|
589 |
'The image features a stack of pancakes with syrup and strawberries on top. The pancakes are arranged in a visually appealing manner, with some pancakes placed on top of each other. The syrup is drizzled generously over the pancakes, and the strawberries are scattered around, adding a touch of color and freshness to the scene. The overall presentation of the pancakes is appetizing and inviting.',
|
590 |
'Instagram Posts',
|
591 |
'brown, peach, grey, modern, minimalist, simple, colorful, illustration, Instagram post, instagram, post, national pancake day, international pancake day, happy pancake day, pancake day, pancake, sweet, cake, discount, sale',
|
@@ -594,9 +605,11 @@ def main():
|
|
594 |
'Get 75% Discount for your first order**********Order Now**********National Pancake Day',
|
595 |
'[0.043161094224924014, 0.5963525835866261, 0.2936170212765957, 0.08389057750759879]; [0.12279635258358662, 0.79209726443769, 0.26382978723404255, 0.05167173252279635]; [0.044984802431610946, 0.09787234042553192, 0.4413373860182371, 0.4158054711246201]',
|
596 |
1,
|
|
|
597 |
]
|
598 |
],
|
599 |
inputs=[
|
|
|
600 |
bg_prompt,
|
601 |
bg_class,
|
602 |
bg_tags,
|
@@ -605,6 +618,7 @@ def main():
|
|
605 |
text_str,
|
606 |
box_str,
|
607 |
seed_,
|
|
|
608 |
],
|
609 |
outputs=[post_box, box_sketch_template, seed_, *color_row, *colors, *styles, *prompts],
|
610 |
fn=process_example,
|
|
|
346 |
return [gr.update(visible=True), *visibilities]
|
347 |
|
348 |
@torch.inference_mode()
|
349 |
+
@spaces.GPU(enable_queue=True, duration=30)
|
350 |
+
def generate_image(bg_prompt, bg_class, bg_tags, seed, cfg, *conditions):
|
351 |
|
352 |
stack_cp = deepcopy(stack)
|
353 |
print(f"conditions: {conditions}")
|
|
|
408 |
texts=prompts,
|
409 |
bboxes=bboxes,
|
410 |
num_inference_steps=50,
|
411 |
+
guidance_scale=cfg,
|
412 |
generator=generator,
|
413 |
text_attn_mask=None,
|
414 |
).images[0]
|
|
|
417 |
|
418 |
return image
|
419 |
|
420 |
+
def process_example(prev_img, bg_prompt, bg_class, bg_tags, color_str, style_str, text_str, box_str, seed, cfg):
|
421 |
global stack
|
422 |
global state
|
423 |
+
print("CHANGE EXAMPLE!!!")
|
424 |
|
425 |
colors = color_str.split(",")
|
426 |
styles = style_str.split(",")
|
|
|
540 |
))
|
541 |
|
542 |
seed_ = gr.Slider(label="Seed", minimum=0, maximum=2147483647, value=42, step=1)
|
543 |
+
cfg_ = gr.Slider(label="CFG Scale", minimum=1, maximum=10, value=5)
|
544 |
button_generate = gr.Button("(2) I've finished my texts, colors and styles, generate!", elem_id="main_button", interactive=True, variant='primary')
|
545 |
|
546 |
button_layout.click(process_box, inputs=[], outputs=[post_box, *color_row])
|
|
|
548 |
with gr.Column():
|
549 |
output_image = gr.Image(label="Output Image", interactive=False)
|
550 |
|
551 |
+
button_generate.click(generate_image, inputs=[bg_prompt, bg_class, bg_tags, seed_, cfg_, *(prompts + colors + styles)], outputs=[output_image], queue=True)
|
552 |
|
553 |
# examples
|
554 |
color_str = gr.Textbox(label="Color list", value="", visible=False)
|
555 |
style_str = gr.Textbox(label="Font type list", value="", visible=False)
|
556 |
box_str = gr.Textbox(label="Bbox list", value="", visible=False)
|
557 |
text_str = gr.Textbox(label="Text list", value="", visible=False)
|
558 |
+
prev_img = gr.Image(label="Preview", visible = False)
|
559 |
|
560 |
gr.Examples(
|
561 |
examples=[
|
562 |
[
|
563 |
+
'assets/previews/image1.webp',
|
564 |
'The image features a small bunny rabbit sitting in a basket filled with various flowers. The basket is placed on a yellow background, creating a vibrant and cheerful scene. The flowers surrounding the rabbit come in different sizes and colors, adding to the overall visual appeal of the image. The rabbit appears to be the main focus of the scene, and its presence among the flowers creates a sense of harmony and balance.',
|
565 |
'Facebook Post',
|
566 |
'green, yellow, minimalist, easter day, happy easter day, easter, happy easter, decoration, happy, egg, spring, selebration, poster, illustration, greeting, season, design, colorful, cute, template',
|
|
|
569 |
'MAY ALLYOUR PRAYERS BE ANSWERED**********HAVE A HAPPY**********Easter Day',
|
570 |
'[0.08267477203647416, 0.5355623100303951, 0.42857142857142855, 0.07477203647416414]; [0.08389057750759879, 0.1951367781155015, 0.38054711246200607, 0.03768996960486322]; [0.07537993920972644, 0.2601823708206687, 0.49544072948328266, 0.14650455927051673]',
|
571 |
1,
|
572 |
+
5
|
573 |
],
|
574 |
[
|
575 |
+
'assets/previews/image2.webp',
|
576 |
'The image features a large gray elephant sitting in a field of flowers, holding a smaller elephant in its arms. The scene is quite serene and picturesque, with the two elephants being the main focus of the image. The field is filled with various flowers, creating a beautiful and vibrant backdrop for the elephants.',
|
577 |
'Cards and invitations',
|
578 |
'Light green, orange, Illustration, watercolor, playful, Baby shower invitation, baby boy shower invitation, baby boy, welcoming baby boy, koala baby shower invitation, baby shower invitation for baby shower, baby boy invitation, background, playful baby shower card, baby shower, card, newborn, born, Baby Shirt Baby Shower Invitation',
|
|
|
581 |
"RSVP to +123-456-7890**********Olivia Wilson**********Baby Shower**********Please Join Us For a**********In Honoring**********23 November, 2021 | 03:00 PM Fauget Hotels",
|
582 |
'[0.07112462006079028, 0.6462006079027356, 0.3373860182370821, 0.026747720364741642]; [0.07051671732522796, 0.38662613981762917, 0.37264437689969604, 0.059574468085106386]; [0.07234042553191489, 0.15623100303951368, 0.6547112462006079, 0.12401215805471125]; [0.0662613981762918, 0.06747720364741641, 0.3981762917933131, 0.035866261398176294]; [0.07051671732522796, 0.31550151975683893, 0.22006079027355624, 0.03951367781155015]; [0.06990881458966565, 0.48328267477203646, 0.39878419452887537, 0.1094224924012158]',
|
583 |
1,
|
584 |
+
5
|
585 |
],
|
586 |
[
|
587 |
+
'assets/previews/image3.webp',
|
588 |
'The image features a white background with a variety of colorful flowers and decorations. There are several pink flowers scattered throughout the scene, with some positioned closer to the top and others near the bottom. A blue flower can also be seen in the middle of the image. The overall composition creates a visually appealing and vibrant display.',
|
589 |
'Instagram Posts',
|
590 |
'grey, navy, purple, pink, teal, colorful, illustration, happy, celebration, post, party, year, new, event, celebrate, happy new year, new year, countdown, sparkle, firework',
|
|
|
592 |
'Caveat-Regular, Gagalin-Regular, Quicksand-Light, Quicksand-Light',
|
593 |
'Happy New Year**********2024**********All THE BEST**********A fresh start to start a change for the better.',
|
594 |
'[0.2936170212765957, 0.2887537993920973, 0.40303951367781155, 0.07173252279635259]; [0.24984802431610942, 0.3951367781155015, 0.46200607902735563, 0.17203647416413373]; [0.3951367781155015, 0.1094224924012158, 0.2109422492401216, 0.02796352583586626]; [0.20911854103343466, 0.6127659574468085, 0.5586626139817629, 0.08085106382978724]',
|
595 |
+
0,
|
596 |
+
5
|
597 |
],
|
598 |
[
|
599 |
+
'assets/previews/image4.webp',
|
600 |
'The image features a stack of pancakes with syrup and strawberries on top. The pancakes are arranged in a visually appealing manner, with some pancakes placed on top of each other. The syrup is drizzled generously over the pancakes, and the strawberries are scattered around, adding a touch of color and freshness to the scene. The overall presentation of the pancakes is appetizing and inviting.',
|
601 |
'Instagram Posts',
|
602 |
'brown, peach, grey, modern, minimalist, simple, colorful, illustration, Instagram post, instagram, post, national pancake day, international pancake day, happy pancake day, pancake day, pancake, sweet, cake, discount, sale',
|
|
|
605 |
'Get 75% Discount for your first order**********Order Now**********National Pancake Day',
|
606 |
'[0.043161094224924014, 0.5963525835866261, 0.2936170212765957, 0.08389057750759879]; [0.12279635258358662, 0.79209726443769, 0.26382978723404255, 0.05167173252279635]; [0.044984802431610946, 0.09787234042553192, 0.4413373860182371, 0.4158054711246201]',
|
607 |
1,
|
608 |
+
5
|
609 |
]
|
610 |
],
|
611 |
inputs=[
|
612 |
+
prev_img,
|
613 |
bg_prompt,
|
614 |
bg_class,
|
615 |
bg_tags,
|
|
|
618 |
text_str,
|
619 |
box_str,
|
620 |
seed_,
|
621 |
+
cfg_
|
622 |
],
|
623 |
outputs=[post_box, box_sketch_template, seed_, *color_row, *colors, *styles, *prompts],
|
624 |
fn=process_example,
|
assets/previews/image1.webp
ADDED
assets/previews/image2.webp
ADDED
assets/previews/image3.webp
ADDED
assets/previews/image4.webp
ADDED