Spaces:
Build error
Build error
File size: 37,580 Bytes
a1ca2de 66a708b a1ca2de ceefdf5 a1ca2de ceefdf5 a1ca2de ceefdf5 a1ca2de ceefdf5 a1ca2de ceefdf5 a1ca2de eb50f40 ceefdf5 a1ca2de 707d418 a1ca2de ceefdf5 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de ceefdf5 a1ca2de ceefdf5 a1ca2de ceefdf5 a1ca2de ceefdf5 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de eb50f40 a1ca2de 66a708b ceefdf5 0bddfdb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 |
import copy
import random
import gradio as gr
from constants.css import STYLE
from constants.init_values import (
genres, places, moods, jobs, ages, mbtis, random_names, personalities, default_character_images, styles
)
from constants import desc
from interfaces import (
ui, chat_ui, story_gen_ui, view_change_ui, export_ui
)
from modules.palmchat import GradioPaLMChatPPManager
with gr.Blocks(css=STYLE) as demo:
chat_mode = gr.State("setting_chat")
chat_state = gr.State({
"setting_chat": GradioPaLMChatPPManager(),
"story_chat": GradioPaLMChatPPManager(),
"export_chat": GradioPaLMChatPPManager(),
})
cur_cursor = gr.State(0)
cursors = gr.State([])
gallery_images1 = gr.State(default_character_images)
gallery_images2 = gr.State(default_character_images)
gallery_images3 = gr.State(default_character_images)
gallery_images4 = gr.State(default_character_images)
selected_main_char_image1 = gr.State(default_character_images[0])
selected_side_char_image1 = gr.State(default_character_images[0])
selected_side_char_image2 = gr.State(default_character_images[0])
selected_side_char_image3 = gr.State(default_character_images[0])
with gr.Column(visible=True) as pre_phase:
gr.Markdown("# π Zero2Story", elem_classes=["markdown-center"])
gr.Markdown(desc.pre_phase_description, elem_classes=["markdown-justify"])
pre_to_setup_btn = gr.Button("create a custom story", elem_classes=["wrap", "control-button"])
with gr.Column(visible=False) as background_setup_phase:
gr.Markdown("# π World setup", elem_classes=["markdown-center"])
gr.Markdown(desc.background_setup_phase_description, elem_classes=["markdown-justify"])
with gr.Row():
with gr.Column():
genre_dd = gr.Dropdown(label="genre", choices=genres, value=genres[0], interactive=True, elem_classes=["center-label"])
with gr.Column():
place_dd = gr.Dropdown(label="place", choices=places["Middle Ages"], value=places["Middle Ages"][0], allow_custom_value=True, interactive=True, elem_classes=["center-label"])
with gr.Column():
mood_dd = gr.Dropdown(label="mood", choices=moods["Middle Ages"], value=moods["Middle Ages"][0], allow_custom_value=True, interactive=True, elem_classes=["center-label"])
with gr.Row():
back_to_pre_btn = gr.Button("β back", elem_classes=["wrap", "control-button"], scale=1)
world_setup_confirm_btn = gr.Button("character setup β", elem_classes=["wrap", "control-button"], scale=2)
with gr.Column(visible=False) as character_setup_phase:
gr.Markdown("# π₯ Character setup")
gr.Markdown(desc.character_setup_phase_description, elem_classes=["markdown-justify"])
with gr.Row():
with gr.Column():
gr.Checkbox(label="character include/enable", value=True, interactive=False)
char_gallery1 = gr.Gallery(value=default_character_images, height=256, preview=True)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("name", elem_classes=["markdown-left"], scale=3)
name_txt1 = gr.Textbox(random_names[0], elem_classes=["no-label"], scale=3)
random_name_btn1 = gr.Button("π³οΈ", elem_classes=["wrap", "control-button-green", "left-margin"], scale=1)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("age", elem_classes=["markdown-left"], scale=3)
age_dd1 = gr.Dropdown(label=None, choices=ages, value=ages[0], elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("mbti", elem_classes=["markdown-left"], scale=3)
mbti_dd1 = gr.Dropdown(label=None, choices=mbtis, value=mbtis[0], interactive=True, elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("nature", elem_classes=["markdown-left"], scale=3)
personality_dd1 = gr.Dropdown(label=None, choices=personalities, value=personalities[0], interactive=True, elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("job", elem_classes=["markdown-left"], scale=3)
job_dd1 = gr.Dropdown(label=None, choices=jobs["Middle Ages"], value=jobs["Middle Ages"][0], allow_custom_value=True, interactive=True, elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"], visible=False):
gr.Markdown("style", elem_classes=["markdown-left"], scale=3)
creative_dd1 = gr.Dropdown(choices=styles, value=styles[0], allow_custom_value=True, interactive=True, elem_classes=["no-label"], scale=4)
gen_char_btn1 = gr.Button("gen character", elem_classes=["wrap", "control-button-green"])
with gr.Column():
side_char_enable_ckb1 = gr.Checkbox(label="character include/enable", value=False)
char_gallery2 = gr.Gallery(value=default_character_images, height=256, preview=True)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("name", elem_classes=["markdown-left"], scale=3)
name_txt2 = gr.Textbox(random_names[1], elem_classes=["no-label"], scale=3)
random_name_btn2 = gr.Button("π³οΈ", elem_classes=["wrap", "control-button-green", "left-margin"], scale=1)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("age", elem_classes=["markdown-left"], scale=3)
age_dd2 = gr.Dropdown(label=None, choices=ages, value=ages[1], elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("mbti", elem_classes=["markdown-left"], scale=3)
mbti_dd2 = gr.Dropdown(label=None, choices=mbtis, value=mbtis[1], interactive=True, elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("nature", elem_classes=["markdown-left"], scale=3)
personality_dd2 = gr.Dropdown(label=None, choices=personalities, value=personalities[1], interactive=True, elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("job", elem_classes=["markdown-left"], scale=3)
job_dd2 = gr.Dropdown(label=None, choices=jobs["Middle Ages"], value=jobs["Middle Ages"][1], allow_custom_value=True, interactive=True, elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"], visible=False):
gr.Markdown("style", elem_classes=["markdown-left"], scale=3)
creative_dd2 = gr.Dropdown(choices=styles, value=styles[0], allow_custom_value=True, interactive=True, elem_classes=["no-label"], scale=4)
gen_char_btn2 = gr.Button("gen character", elem_classes=["wrap", "control-button-green"])
with gr.Column():
side_char_enable_ckb2 = gr.Checkbox(label="character include/enable", value=False)
char_gallery3 = gr.Gallery(value=default_character_images, height=256, preview=True)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("name", elem_classes=["markdown-left"], scale=3)
name_txt3 = gr.Textbox(random_names[2], elem_classes=["no-label"], scale=3)
random_name_btn3 = gr.Button("π³οΈ", elem_classes=["wrap", "control-button-green", "left-margin"], scale=1)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("age", elem_classes=["markdown-left"], scale=3)
age_dd3 = gr.Dropdown(label=None, choices=ages, value=ages[2], elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("mbti", elem_classes=["markdown-left"], scale=3)
mbti_dd3 = gr.Dropdown(label=None, choices=mbtis, value=mbtis[2], interactive=True, elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("nature", elem_classes=["markdown-left"], scale=3)
personality_dd3 = gr.Dropdown(label=None, choices=personalities, value=personalities[2], interactive=True, elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("job", elem_classes=["markdown-left"], scale=3)
job_dd3 = gr.Dropdown(label=None, choices=jobs["Middle Ages"], value=jobs["Middle Ages"][2], allow_custom_value=True, interactive=True, elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"], visible=False):
gr.Markdown("style", elem_classes=["markdown-left"], scale=3)
creative_dd3 = gr.Dropdown(choices=styles, value=styles[0], allow_custom_value=True, interactive=True, elem_classes=["no-label"], scale=4)
gen_char_btn3 = gr.Button("gen character", elem_classes=["wrap", "control-button-green"])
with gr.Column():
side_char_enable_ckb3 = gr.Checkbox(label="character include/enable", value=False)
char_gallery4 = gr.Gallery(value=default_character_images, height=256, preview=True)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("name", elem_classes=["markdown-left"], scale=3)
name_txt4 = gr.Textbox(random_names[3], elem_classes=["no-label"], scale=3)
random_name_btn4 = gr.Button("π³οΈ", elem_classes=["wrap", "control-button-green", "left-margin"], scale=1)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("age", elem_classes=["markdown-left"], scale=3)
age_dd4 = gr.Dropdown(label=None, choices=ages, value=ages[3], elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("mbti", elem_classes=["markdown-left"], scale=3)
mbti_dd4 = gr.Dropdown(label=None, choices=mbtis, value=mbtis[3], interactive=True, elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("nature", elem_classes=["markdown-left"], scale=3)
personality_dd4 = gr.Dropdown(label=None, choices=personalities, value=personalities[3], interactive=True, elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"]):
gr.Markdown("job", elem_classes=["markdown-left"], scale=3)
job_dd4 = gr.Dropdown(label=None, choices=jobs["Middle Ages"], value=jobs["Middle Ages"][3], allow_custom_value=True, interactive=True, elem_classes=["no-label"], scale=4)
with gr.Row(elem_classes=["no-gap"], visible=False):
gr.Markdown("style", elem_classes=["markdown-left"], scale=3)
creative_dd4 = gr.Dropdown(choices=styles, value=styles[0], allow_custom_value=True, interactive=True, elem_classes=["no-label"], scale=4)
gen_char_btn4 = gr.Button("gen character", elem_classes=["wrap", "control-button-green"])
with gr.Row():
back_to_background_setup_btn = gr.Button("β back", elem_classes=["wrap", "control-button"], scale=1)
character_setup_confirm_btn = gr.Button("generate first stories β", elem_classes=["wrap", "control-button"], scale=2)
gr.Markdown("### π‘ Plot setup", visible=False)
with gr.Accordion("generate chapter titles and each plot", open=False, visible=False) as plot_setup_section:
title = gr.Textbox("Title Undetermined Yet", elem_classes=["no-label", "font-big"])
# plot = gr.Textbox(lines=10, elem_classes=["no-label", "small-big-textarea"])
gr.Textbox("Rising action", elem_classes=["no-label"])
with gr.Row(elem_classes=["left-margin"]):
chapter1_plot = gr.Textbox(placeholder="The plot of the first chapter will be generated here", lines=3, elem_classes=["no-label"])
gr.Textbox("Crisis", elem_classes=["no-label"])
with gr.Row(elem_classes=["left-margin"]):
chapter2_plot = gr.Textbox(placeholder="The plot of the second chapter will be generated here", lines=3, elem_classes=["no-label"])
gr.Textbox("Climax", elem_classes=["no-label"])
with gr.Row(elem_classes=["left-margin"]):
chapter3_plot = gr.Textbox(placeholder="The plot of the third chapter will be generated here", lines=3, elem_classes=["no-label"])
gr.Textbox("Falling action", elem_classes=["no-label"])
with gr.Row(elem_classes=["left-margin"]):
chapter4_plot = gr.Textbox(placeholder="The plot of the fourth chapter will be generated here", lines=3, elem_classes=["no-label"])
gr.Textbox("Denouement", elem_classes=["no-label"])
with gr.Row(elem_classes=["left-margin"]):
chapter5_plot = gr.Textbox(placeholder="The plot of the fifth chapter will be generated here", lines=3, elem_classes=["no-label"])
with gr.Row():
plot_gen_temp = gr.Slider(0.0, 2.0, 1.0, step=0.1, label="temperature")
plot_gen_btn = gr.Button("gen plot", elem_classes=["control-button"])
plot_setup_confirm_btn = gr.Button("confirm", elem_classes=["control-button"])
with gr.Column(visible=False) as writing_phase:
gr.Markdown("# βπΌ Story writing")
gr.Markdown(desc.story_generation_phase_description, elem_classes=["markdown-justify"])
progress_comp = gr.Textbox(label=None, elem_classes=["no-label"], interactive=False)
title_display = gr.Markdown("# Title Undetermined Yet", elem_classes=["markdown-center"], visible=False)
subtitle_display = gr.Markdown("### Title Undetermined Yet", elem_classes=["markdown-center"], visible=False)
with gr.Row():
image_gen_btn = gr.Button("ποΈ Image", interactive=False, elem_classes=["control-button-green"])
audio_gen_btn = gr.Button("π Audio", interactive=False, elem_classes=["control-button-green"])
img_audio_combine_btn = gr.Button("π Image + Audio", interactive=False, elem_classes=["control-button-green"])
story_image = gr.Image(None, visible=False, type="filepath", interactive=False, elem_classes=["no-label-image-audio"])
story_audio = gr.Audio(None, visible=False, type="filepath", interactive=False, elem_classes=["no-label-image-audio"])
story_video = gr.Video(visible=False, interactive=False, elem_classes=["no-label-gallery"])
story_progress = gr.Slider(
1, 2, 1, step=1, interactive=True,
label="1/2", visible=False
)
story_content = gr.Textbox(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer interdum eleifend tincidunt. Vivamus dapibus, massa ut imperdiet condimentum, quam ipsum vehicula eros, a accumsan nisl metus at nisl. Nullam tortor nibh, vehicula sed tellus at, accumsan efficitur enim. Sed mollis purus vitae nisl ornare volutpat. In vitae tortor nec neque sagittis vehicula. In vestibulum velit eu lorem pulvinar dignissim. Donec eu sapien et sapien cursus pretium elementum eu urna. Proin lacinia ipsum maximus, commodo dui tempus, convallis tortor. Nulla sodales mi libero, nec eleifend eros interdum quis. Pellentesque nulla lectus, scelerisque et consequat vitae, blandit at ante. Sed nec β¦β¦.",
lines=12,
elem_classes=["no-label", "small-big-textarea"]
)
with gr.Accordion("regeneration controls", open=False):
with gr.Row():
regen_actions_btn = gr.Button("Re-suggest actions", interactive=True, elem_classes=["control-button-green"])
regen_story_btn = gr.Button("Re-suggest story and actions", interactive=True, elem_classes=["control-button-green"])
custom_prompt_txt = gr.Textbox(placeholder="Re-suggest story and actions based on your own custom request", interactive=True, elem_classes=["no-label", "small-big-textarea"])
with gr.Row():
action_btn1 = gr.Button("Action Choice 1", interactive=False, elem_classes=["control-button-green"])
action_btn2 = gr.Button("Action Choice 2", interactive=False, elem_classes=["control-button-green"])
action_btn3 = gr.Button("Action Choice 3", interactive=False, elem_classes=["control-button-green"])
custom_action_txt = gr.Textbox(placeholder="write your own custom action", elem_classes=["no-label", "small-big-textarea"], scale=3)
with gr.Row():
restart_from_story_generation_btn = gr.Button("β back", elem_classes=["wrap", "control-button"], scale=1)
story_writing_done_btn = gr.Button("export your story β", elem_classes=["wrap", "control-button"], scale=2)
with gr.Column(visible=False) as export_phase:
gr.Markdown("# π€ Export your story")
gr.Markdown(desc.export_phase_description, elem_classes=["markdown-justify"])
title_txt = gr.Textbox("Your Own Story", elem_classes=["no-label"])
title_gen_btn = gr.Button("gnerate a title", elem_classes=["control-button-green"])
with gr.Row():
back_to_story_writing_btn = gr.Button("β back", elem_classes=["wrap", "control-button"], scale=1)
restart_from_export_btn = gr.Button("start over", elem_classes=["wrap", "control-button"], scale=1)
export_done_btn = gr.Button("exported story β", elem_classes=["wrap", "control-button"], scale=1)
with gr.Column(visible=False) as export_view_phase:
export_html = gr.HTML()
with gr.Row():
restart_from_export_view_btn = gr.Button("start over", elem_classes=["wrap", "control-button"])
export_to_file_btn = gr.Button("Download as ZIP file", elem_classes=["wrap", "control-button"], scale=2)
with gr.Accordion("π¬", open=False, elem_id="chat-section", visible=False) as chat_section:
with gr.Column(scale=1):
chatbot = gr.Chatbot(
[],
avatar_images=("assets/user.png", "assets/ai.png"),
elem_id="chatbot",
elem_classes=["no-label-chatbot"])
chat_input_txt = gr.Textbox(placeholder="enter...", interactive=True, elem_id="chat-input", elem_classes=["no-label"])
with gr.Row(elem_id="chat-buttons"):
regen_btn = gr.Button("regen", interactive=False, elem_classes=["control-button"])
clear_btn = gr.Button("clear", elem_classes=["control-button"])
pre_to_setup_btn.click(
view_change_ui.move_to_next_view,
inputs=None,
outputs=[pre_phase, background_setup_phase]
)
back_to_pre_btn.click(
view_change_ui.back_to_previous_view,
inputs=None,
outputs=[pre_phase, background_setup_phase]
)
world_setup_confirm_btn.click(
view_change_ui.move_to_next_view,
inputs=None,
outputs=[background_setup_phase, character_setup_phase]
)
back_to_background_setup_btn.click(
view_change_ui.back_to_previous_view,
inputs=None,
outputs=[background_setup_phase, character_setup_phase]
)
restart_from_story_generation_btn.click(
view_change_ui.move_to_next_view,
inputs=None,
outputs=[pre_phase, writing_phase]
)
story_writing_done_btn.click(
view_change_ui.move_to_next_view,
inputs=None,
outputs=[writing_phase, export_phase]
)
title_gen_btn.click(
export_ui.title_gen,
inputs=[cursors],
outputs=[title_txt]
)
export_done_btn.click(
view_change_ui.move_to_next_view,
inputs=None,
outputs=[export_phase, export_view_phase]
).then(
export_ui.export,
inputs=[
title_txt,
cursors,
selected_main_char_image1, name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, selected_side_char_image1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, selected_side_char_image2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, selected_side_char_image3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
export_html
]
)
back_to_story_writing_btn.click(
view_change_ui.back_to_previous_view,
inputs=None,
outputs=[writing_phase, export_phase]
)
restart_from_export_view_btn.click(
view_change_ui.back_to_previous_view,
inputs=None,
outputs=[pre_phase, export_view_phase]
).then(
ui.reset,
inputs=None,
outputs=[
cursors, cur_cursor,
chat_state, chat_mode,
gallery_images1, gallery_images2, gallery_images3, gallery_images4,
selected_main_char_image1, selected_side_char_image1, selected_side_char_image2, selected_side_char_image3,
genre_dd, place_dd, mood_dd,
char_gallery1, job_dd1,
side_char_enable_ckb1, char_gallery2, job_dd2,
side_char_enable_ckb2, char_gallery3, job_dd3,
side_char_enable_ckb3, char_gallery4, job_dd4,
story_image, story_audio, story_video,
story_content, story_progress,
custom_prompt_txt, action_btn1, action_btn2, action_btn3, custom_action_txt,
title_txt, export_html
]
)
restart_from_export_btn.click(
view_change_ui.back_to_previous_view,
inputs=None,
outputs=[pre_phase, export_phase]
).then(
ui.reset,
inputs=None,
outputs=[
cursors, cur_cursor,
chat_state, chat_mode,
gallery_images1, gallery_images2, gallery_images3, gallery_images4,
selected_main_char_image1, selected_side_char_image1, selected_side_char_image2, selected_side_char_image3,
genre_dd, place_dd, mood_dd,
char_gallery1, job_dd1,
side_char_enable_ckb1, char_gallery2, job_dd2,
side_char_enable_ckb2, char_gallery3, job_dd3,
side_char_enable_ckb3, char_gallery4, job_dd4,
story_image, story_audio, story_video,
story_content, story_progress,
custom_prompt_txt, action_btn1, action_btn2, action_btn3, custom_action_txt,
title_txt, export_html
]
)
character_setup_confirm_btn.click(
view_change_ui.move_to_next_view,
inputs=None,
outputs=[character_setup_phase, writing_phase]
).then(
story_gen_ui.disable_btns,
inputs=None,
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
).then(
story_gen_ui.first_story_gen,
inputs=[
cursors,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
cursors, cur_cursor, story_content, story_progress, image_gen_btn, audio_gen_btn,
story_image, story_audio, story_video
]
).then(
story_gen_ui.actions_gen,
inputs=[
cursors,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
action_btn1, action_btn2, action_btn3, progress_comp
]
).then(
story_gen_ui.enable_btns,
inputs=[story_image, story_audio],
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
)
regen_actions_btn.click(
story_gen_ui.disable_btns,
inputs=None,
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
).then(
story_gen_ui.actions_gen,
inputs=[
cursors,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
action_btn1, action_btn2, action_btn3, progress_comp
]
).then(
story_gen_ui.enable_btns,
inputs=[story_image, story_audio],
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
)
regen_story_btn.click(
story_gen_ui.disable_btns,
inputs=None,
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
).then(
story_gen_ui.update_story_gen,
inputs=[
cursors, cur_cursor,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
cursors, cur_cursor, story_content, story_progress, image_gen_btn, audio_gen_btn
]
).then(
story_gen_ui.actions_gen,
inputs=[
cursors,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
action_btn1, action_btn2, action_btn3, progress_comp
]
).then(
story_gen_ui.enable_btns,
inputs=[story_image, story_audio],
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
)
#### Setups
genre_dd.select(
ui.update_on_age,
outputs=[place_dd, mood_dd, job_dd1, job_dd2, job_dd3, job_dd4]
)
gen_char_btn1.click(
ui.gen_character_image,
inputs=[
gallery_images1, name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1, genre_dd, place_dd, mood_dd, creative_dd1],
outputs=[char_gallery1, gallery_images1, selected_main_char_image1]
)
gen_char_btn2.click(
ui.gen_character_image,
inputs=[gallery_images2, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2, genre_dd, place_dd, mood_dd, creative_dd2],
outputs=[char_gallery2, gallery_images2, selected_side_char_image1]
)
gen_char_btn3.click(
ui.gen_character_image,
inputs=[gallery_images3, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3, genre_dd, place_dd, mood_dd, creative_dd3],
outputs=[char_gallery3, gallery_images3, selected_side_char_image2]
)
gen_char_btn4.click(
ui.gen_character_image,
inputs=[gallery_images4, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4, genre_dd, place_dd, mood_dd, creative_dd4],
outputs=[char_gallery4, gallery_images4, selected_side_char_image3]
)
random_name_btn1.click(
ui.get_random_name,
inputs=[name_txt1, name_txt2, name_txt3, name_txt4],
outputs=[name_txt1],
)
random_name_btn2.click(
ui.get_random_name,
inputs=[name_txt2, name_txt1, name_txt3, name_txt4],
outputs=[name_txt2],
)
random_name_btn3.click(
ui.get_random_name,
inputs=[name_txt3, name_txt1, name_txt2, name_txt4],
outputs=[name_txt3],
)
random_name_btn4.click(
ui.get_random_name,
inputs=[name_txt4, name_txt1, name_txt2, name_txt3],
outputs=[name_txt4],
)
### Story generation
story_content.input(
story_gen_ui.update_story_content,
inputs=[story_content, cursors, cur_cursor],
outputs=[cursors],
)
image_gen_btn.click(
story_gen_ui.disable_btns,
inputs=None,
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
).then(
story_gen_ui.image_gen,
inputs=[
genre_dd, place_dd, mood_dd, title, story_content, cursors, cur_cursor
],
outputs=[
story_image, cursors, progress_comp,
]
).then(
story_gen_ui.enable_btns,
inputs=[story_image, story_audio],
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
)
audio_gen_btn.click(
story_gen_ui.disable_btns,
inputs=None,
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
).then(
story_gen_ui.audio_gen,
inputs=[
genre_dd, place_dd, mood_dd, title, story_content, cursors, cur_cursor
],
outputs=[story_audio, cursors, progress_comp]
).then(
story_gen_ui.enable_btns,
inputs=[story_image, story_audio],
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
)
img_audio_combine_btn.click(
story_gen_ui.disable_btns,
inputs=None,
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
).then(
story_gen_ui.video_gen,
inputs=[
story_image, story_audio, story_content, cursors, cur_cursor
],
outputs=[
story_image, story_audio, story_video, cursors, progress_comp
],
).then(
story_gen_ui.enable_btns,
inputs=[story_image, story_audio],
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
)
story_progress.input(
story_gen_ui.move_story_cursor,
inputs=[
story_progress, cursors
],
outputs=[
cur_cursor,
story_progress,
story_content,
story_image, story_audio, story_video,
action_btn1, action_btn2, action_btn3,
]
)
action_btn1.click(
story_gen_ui.disable_btns,
inputs=None,
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
).then(
story_gen_ui.next_story_gen,
inputs=[
cursors,
action_btn1,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
cursors, cur_cursor,
story_content, story_progress,
image_gen_btn, audio_gen_btn,
story_image, story_audio, story_video
]
).then(
story_gen_ui.actions_gen,
inputs=[
cursors,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
action_btn1, action_btn2, action_btn3, progress_comp
]
).then(
story_gen_ui.enable_btns,
inputs=[story_image, story_audio],
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
)
action_btn2.click(
story_gen_ui.disable_btns,
inputs=None,
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
).then(
story_gen_ui.next_story_gen,
inputs=[
cursors,
action_btn2,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
cursors, cur_cursor,
story_content, story_progress,
image_gen_btn, audio_gen_btn,
story_image, story_audio, story_video
]
).then(
story_gen_ui.actions_gen,
inputs=[
cursors,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
action_btn1, action_btn2, action_btn3, progress_comp
]
).then(
story_gen_ui.enable_btns,
inputs=[story_image, story_audio],
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
)
action_btn3.click(
story_gen_ui.disable_btns,
inputs=None,
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
).then(
story_gen_ui.next_story_gen,
inputs=[
cursors,
action_btn3,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
cursors, cur_cursor,
story_content, story_progress,
image_gen_btn, audio_gen_btn,
story_image, story_audio, story_video
]
).then(
story_gen_ui.actions_gen,
inputs=[
cursors,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
action_btn1, action_btn2, action_btn3, progress_comp
]
).then(
story_gen_ui.enable_btns,
inputs=[story_image, story_audio],
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
)
custom_action_txt.submit(
story_gen_ui.disable_btns,
inputs=None,
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
).then(
story_gen_ui.next_story_gen,
inputs=[
cursors,
custom_action_txt,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
cursors, cur_cursor,
story_content, story_progress,
image_gen_btn, audio_gen_btn,
story_image, story_audio, story_video
]
).then(
story_gen_ui.actions_gen,
inputs=[
cursors,
genre_dd, place_dd, mood_dd,
name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
side_char_enable_ckb1, name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
side_char_enable_ckb2, name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
side_char_enable_ckb3, name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
],
outputs=[
action_btn1, action_btn2, action_btn3, progress_comp
]
).then(
story_gen_ui.enable_btns,
inputs=[story_image, story_audio],
outputs=[
image_gen_btn, audio_gen_btn, img_audio_combine_btn,
regen_actions_btn, regen_story_btn, custom_prompt_txt,
action_btn1, action_btn2, action_btn3,
custom_action_txt,
restart_from_story_generation_btn, story_writing_done_btn
]
)
### Chatbot
# chat_input_txt.submit(
# chat_ui.chat,
# inputs=[
# chat_input_txt, chat_mode, chat_state,
# genre_dd, place_dd, mood_dd,
# name_txt1, age_dd1, mbti_dd1, personality_dd1, job_dd1,
# name_txt2, age_dd2, mbti_dd2, personality_dd2, job_dd2,
# name_txt3, age_dd3, mbti_dd3, personality_dd3, job_dd3,
# name_txt4, age_dd4, mbti_dd4, personality_dd4, job_dd4,
# chapter1_title, chapter2_title, chapter3_title, chapter4_title,
# chapter1_plot, chapter2_plot, chapter3_plot, chapter4_plot
# ],
# outputs=[chat_input_txt, chat_state, chatbot, regen_btn]
# )
regen_btn.click(
chat_ui.rollback_last_ui,
inputs=[chatbot], outputs=[chatbot]
).then(
chat_ui.chat_regen,
inputs=[chat_mode, chat_state],
outputs=[chat_state, chatbot]
)
clear_btn.click(
chat_ui.chat_reset,
inputs=[chat_mode, chat_state],
outputs=[chat_input_txt, chat_state, chatbot, regen_btn]
)
char_gallery1.select(
ui.update_selected_char_image,
inputs=None,
outputs=[selected_main_char_image1]
)
char_gallery2.select(
ui.update_selected_char_image,
inputs=None,
outputs=[selected_side_char_image1]
)
char_gallery3.select(
ui.update_selected_char_image,
inputs=None,
outputs=[selected_side_char_image2]
)
char_gallery4.select(
ui.update_selected_char_image,
inputs=None,
outputs=[selected_side_char_image3]
)
demo.queue().launch()
|