Spaces:
Running
on
Zero
Running
on
Zero
Upload 4 files
Browse files
app.py
CHANGED
@@ -342,13 +342,14 @@ from stablepy import logger
|
|
342 |
logger.setLevel(logging.CRITICAL)
|
343 |
|
344 |
from v2 import (
|
345 |
-
V2UI,
|
346 |
-
parse_upsampling_output,
|
347 |
V2_ALL_MODELS,
|
|
|
|
|
348 |
)
|
349 |
from utils import (
|
350 |
gradio_copy_text,
|
351 |
COPY_ACTION_JS,
|
|
|
352 |
V2_ASPECT_RATIO_OPTIONS,
|
353 |
V2_RATING_OPTIONS,
|
354 |
V2_LENGTH_OPTIONS,
|
@@ -782,6 +783,7 @@ CSS ="""
|
|
782 |
.contain {display: flex; flex-direction: column; !important;}
|
783 |
#component-0 {height: 100%; !important;}
|
784 |
#gallery {flex-grow: 1; !important;}
|
|
|
785 |
"""
|
786 |
## END MOD
|
787 |
|
@@ -811,13 +813,13 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", elem_id="main", css=CSS) as app:
|
|
811 |
)
|
812 |
with gr.Row():
|
813 |
with gr.Tab("Generation"):
|
814 |
-
v2b = V2UI()
|
815 |
with gr.Column():
|
816 |
interface_mode_gui = gr.Radio(label="Quick settings", choices=["Simple", "Standard", "Fast", "LoRA"], value="Standard")
|
817 |
with gr.Accordion("Model and Task", open=False) as menu_model:
|
818 |
task_gui = gr.Dropdown(label="Task", choices=sdxl_task, value=task_model_list[0])
|
819 |
-
|
820 |
-
|
|
|
821 |
with gr.Row():
|
822 |
quick_model_type_gui = gr.Radio(label="Model Type", choices=["None", "Auto", "Animagine", "Pony"], value="Auto", interactive=True)
|
823 |
quick_genre_gui = gr.Radio(label="Genre", choices=["Anime", "Photo"], value="Anime", interactive=True)
|
@@ -828,17 +830,17 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", elem_id="main", css=CSS) as app:
|
|
828 |
style_selector_gui = gr.Dropdown(label="Style Preset", interactive=True, choices=list(preset_styles.keys()), value="None")
|
829 |
sampler_selector_gui = gr.Dropdown(label="Sampler Quick Settings", interactive=True, choices=list(preset_sampler_setting.keys()), value="None")
|
830 |
optimization_gui = gr.Dropdown(label="Optimization for SDXL", choices=list(optimization_list.keys()), value="None", interactive=True)
|
831 |
-
with gr.Accordion("Generate prompt from Image", open=False) as menu_from_image:
|
832 |
-
input_image_gui = gr.Image(label="Input image", type="pil", sources=["upload", "clipboard"], height=256)
|
833 |
-
with gr.Accordion(label="Advanced options", open=False):
|
834 |
-
general_threshold_gui = gr.Slider(label="Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.01, interactive=True)
|
835 |
-
character_threshold_gui = gr.Slider(label="Character threshold", minimum=0.0, maximum=1.0, value=0.8, step=0.01, interactive=True)
|
836 |
-
tag_type_gui = gr.Radio(label="Convert tags to", info="danbooru for Animagine, e621 for Pony.", choices=["danbooru", "e621"], value="danbooru")
|
837 |
-
recom_prompt_gui = gr.Radio(label="Insert reccomended prompt", choices=["None", "Animagine", "Pony"], value="None", interactive=True)
|
838 |
-
keep_tags_gui = gr.Radio(label="Remove tags leaving only the following", choices=["body", "dress", "all"], value="all")
|
839 |
-
image_algorithms = gr.CheckboxGroup(["Use WD Tagger", "Use Florence-2-SD3-Long-Captioner"], label="Algorithms", value=["Use WD Tagger"], visible=False)
|
840 |
-
generate_from_image_btn_gui = gr.Button(value="GENERATE TAGS FROM IMAGE", size="lg", variant="primary")
|
841 |
with gr.Group():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
842 |
prompt_gui = gr.Textbox(lines=6, placeholder="1girl, solo, ...", label="Prompt", show_copy_button=True)
|
843 |
with gr.Accordion("Negative prompt, etc.", open=False) as menu_negative:
|
844 |
neg_prompt_gui = gr.Textbox(lines=3, placeholder="lowres, (bad), ...", label="Negative prompt", show_copy_button=True)
|
@@ -850,21 +852,20 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", elem_id="main", css=CSS) as app:
|
|
850 |
with gr.Row():
|
851 |
character_dbt = gr.Textbox(lines=1, placeholder="kafuu chino, ...", label="Character names")
|
852 |
series_dbt = gr.Textbox(lines=1, placeholder="Is the order a rabbit?, ...", label="Series names")
|
853 |
-
random_character_gui = gr.Button(value="
|
854 |
model_name_dbt = gr.Dropdown(label="Model", choices=list(V2_ALL_MODELS.keys()), value=list(V2_ALL_MODELS.keys())[0], visible=False)
|
855 |
aspect_ratio_dbt = gr.Radio(label="Aspect ratio", choices=list(V2_ASPECT_RATIO_OPTIONS), value="square", visible=False)
|
856 |
length_dbt = gr.Radio(label="Length", choices=list(V2_LENGTH_OPTIONS), value="very_long", visible=False)
|
857 |
identity_dbt = gr.Radio(label="Keep identity", choices=list(V2_IDENTITY_OPTIONS), value="lax", visible=False)
|
858 |
ban_tags_dbt = gr.Textbox(label="Ban tags", placeholder="alternate costumen, ...", value="futanari, censored, furry, furrification", visible=False)
|
859 |
-
elapsed_time_dbt = gr.Markdown(label="Elapsed time", value="", visible=False)
|
860 |
copy_button_dbt = gr.Button(value="Copy to clipboard", visible=False)
|
861 |
-
generate_db_random_button = gr.Button(value="Generate random prompt 🎲", variant="secondary")
|
862 |
rating_dbt = gr.Radio(label="Rating", choices=list(V2_RATING_OPTIONS), value="sfw")
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
|
|
868 |
generate_button = gr.Button(value="GENERATE IMAGE", size="lg", variant="primary")
|
869 |
|
870 |
model_name_gui.change(
|
@@ -1606,16 +1607,16 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", elem_id="main", css=CSS) as app:
|
|
1606 |
).success(
|
1607 |
insert_recom_prompt, [prompt_gui, neg_prompt_gui, recom_prompt_gui], [prompt_gui, neg_prompt_gui], queue=False,
|
1608 |
)
|
1609 |
-
|
1610 |
-
v2b.input_components = [model_name_dbt, series_dbt, character_dbt, prompt_gui,
|
1611 |
-
rating_dbt, aspect_ratio_dbt, length_dbt, identity_dbt, ban_tags_dbt]
|
1612 |
|
1613 |
prompt_type_button.click(convert_danbooru_to_e621_prompt, [prompt_gui, prompt_type_gui], [prompt_gui], queue=False)
|
1614 |
random_character_gui.click(select_random_character, [series_dbt, character_dbt], [series_dbt, character_dbt], queue=False)
|
1615 |
generate_db_random_button.click(
|
1616 |
-
|
1617 |
-
[
|
1618 |
-
|
|
|
|
|
|
|
1619 |
)
|
1620 |
|
1621 |
translate_prompt_button.click(translate_prompt, [prompt_gui], [prompt_gui], queue=False)
|
@@ -1743,7 +1744,6 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", elem_id="main", css=CSS) as app:
|
|
1743 |
).success(save_gallery_images, [result_images], [result_images, result_images_files, result_images_files], queue=False)
|
1744 |
|
1745 |
with gr.Tab("Danbooru Tags Transformer with WD Tagger", render=True):
|
1746 |
-
v2 = V2UI()
|
1747 |
with gr.Column(scale=2):
|
1748 |
with gr.Group():
|
1749 |
input_image = gr.Image(label="Input image", type="pil", sources=["upload", "clipboard"], height=256)
|
@@ -1752,17 +1752,20 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", elem_id="main", css=CSS) as app:
|
|
1752 |
character_threshold = gr.Slider(label="Character threshold", minimum=0.0, maximum=1.0, value=0.8, step=0.01, interactive=True)
|
1753 |
input_tag_type = gr.Radio(label="Convert tags to", info="danbooru for Animagine, e621 for Pony.", choices=["danbooru", "e621"], value="danbooru")
|
1754 |
recom_prompt = gr.Radio(label="Insert reccomended prompt", choices=["None", "Animagine", "Pony"], value="None", interactive=True)
|
1755 |
-
image_algorithms = gr.CheckboxGroup(["Use WD Tagger"
|
1756 |
keep_tags = gr.Radio(label="Remove tags leaving only the following", choices=["body", "dress", "all"], value="all")
|
1757 |
generate_from_image_btn = gr.Button(value="GENERATE TAGS FROM IMAGE", size="lg", variant="primary")
|
1758 |
|
1759 |
with gr.Group():
|
1760 |
-
|
1761 |
-
|
1762 |
-
|
|
|
1763 |
input_general = gr.TextArea(label="General tags", lines=4, placeholder="1girl, ...", value="")
|
1764 |
input_tags_to_copy = gr.Textbox(value="", visible=False)
|
1765 |
-
|
|
|
|
|
1766 |
translate_input_prompt_button = gr.Button(value="Translate prompt to English", size="sm", variant="secondary")
|
1767 |
tag_type = gr.Radio(label="Output tag conversion", info="danbooru for Animagine, e621 for Pony.", choices=["danbooru", "e621"], value="e621", visible=False)
|
1768 |
input_rating = gr.Radio(label="Rating", choices=list(V2_RATING_OPTIONS), value="explicit")
|
@@ -1780,18 +1783,18 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", elem_id="main", css=CSS) as app:
|
|
1780 |
|
1781 |
with gr.Group():
|
1782 |
output_text = gr.TextArea(label="Output tags", interactive=False, show_copy_button=True)
|
1783 |
-
|
1784 |
-
|
|
|
1785 |
|
1786 |
with gr.Group():
|
1787 |
output_text_pony = gr.TextArea(label="Output tags (Pony e621 style)", interactive=False, show_copy_button=True)
|
1788 |
-
|
|
|
|
|
1789 |
|
1790 |
description_ui()
|
1791 |
|
1792 |
-
v2.input_components = [model_name, input_copyright, input_character, input_general,
|
1793 |
-
input_rating, input_aspect_ratio, input_length, input_identity, input_ban_tags]
|
1794 |
-
|
1795 |
translate_input_prompt_button.click(translate_prompt, inputs=[input_general], outputs=[input_general], queue=False)
|
1796 |
translate_input_prompt_button.click(translate_prompt, inputs=[input_character], outputs=[input_character], queue=False)
|
1797 |
translate_input_prompt_button.click(translate_prompt, inputs=[input_copyright], outputs=[input_copyright], queue=False)
|
@@ -1806,25 +1809,31 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", elem_id="main", css=CSS) as app:
|
|
1806 |
convert_danbooru_to_e621_prompt, inputs=[input_general, input_tag_type], outputs=[input_general], queue=False,
|
1807 |
).success(
|
1808 |
insert_recom_prompt, inputs=[input_general, dummy_np, recom_prompt], outputs=[input_general, dummy_np], queue=False,
|
1809 |
-
)
|
1810 |
copy_input_btn.click(compose_prompt_to_copy, inputs=[input_character, input_copyright, input_general], outputs=[input_tags_to_copy])\
|
1811 |
.success(gradio_copy_text, inputs=[input_tags_to_copy], js=COPY_ACTION_JS)
|
1812 |
-
|
|
|
|
|
1813 |
pick_random_character.click(select_random_character, [input_copyright, input_character], [input_copyright, input_character])
|
1814 |
|
1815 |
generate_btn.click(
|
1816 |
-
|
1817 |
-
[
|
1818 |
-
|
|
|
1819 |
).success(
|
1820 |
convert_danbooru_to_e621_prompt, inputs=[output_text, tag_type], outputs=[output_text_pony], queue=False,
|
1821 |
).success(
|
1822 |
insert_recom_prompt, inputs=[output_text, dummy_np, recom_animagine], outputs=[output_text, dummy_np], queue=False,
|
1823 |
).success(
|
1824 |
insert_recom_prompt, inputs=[output_text_pony, dummy_np, recom_pony], outputs=[output_text_pony, dummy_np], queue=False,
|
1825 |
-
)
|
|
|
1826 |
copy_btn.click(gradio_copy_text, inputs=[output_text], js=COPY_ACTION_JS)
|
1827 |
copy_btn_pony.click(gradio_copy_text, inputs=[output_text_pony], js=COPY_ACTION_JS)
|
|
|
|
|
1828 |
|
1829 |
gr.DuplicateButton(value="Duplicate Space for private use (This demo does not work on CPU. Requires Space with GPU available.)", elem_id="duplicate-button", visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1")
|
1830 |
|
|
|
342 |
logger.setLevel(logging.CRITICAL)
|
343 |
|
344 |
from v2 import (
|
|
|
|
|
345 |
V2_ALL_MODELS,
|
346 |
+
v2_random_prompt,
|
347 |
+
v2_upsampling_prompt,
|
348 |
)
|
349 |
from utils import (
|
350 |
gradio_copy_text,
|
351 |
COPY_ACTION_JS,
|
352 |
+
gradio_copy_prompt,
|
353 |
V2_ASPECT_RATIO_OPTIONS,
|
354 |
V2_RATING_OPTIONS,
|
355 |
V2_LENGTH_OPTIONS,
|
|
|
783 |
.contain {display: flex; flex-direction: column; !important;}
|
784 |
#component-0 {height: 100%; !important;}
|
785 |
#gallery {flex-grow: 1; !important;}
|
786 |
+
#model-info { text-align: center; }
|
787 |
"""
|
788 |
## END MOD
|
789 |
|
|
|
813 |
)
|
814 |
with gr.Row():
|
815 |
with gr.Tab("Generation"):
|
|
|
816 |
with gr.Column():
|
817 |
interface_mode_gui = gr.Radio(label="Quick settings", choices=["Simple", "Standard", "Fast", "LoRA"], value="Standard")
|
818 |
with gr.Accordion("Model and Task", open=False) as menu_model:
|
819 |
task_gui = gr.Dropdown(label="Task", choices=sdxl_task, value=task_model_list[0])
|
820 |
+
with gr.Group():
|
821 |
+
model_name_gui = gr.Dropdown(label="Model", info="You can enter a huggingface model repo_id to want to use.", choices=get_tupled_model_list(model_list), value="votepurchase/animagine-xl-3.1", allow_custom_value=True)
|
822 |
+
model_info_gui = gr.Markdown(elem_id="model-info")
|
823 |
with gr.Row():
|
824 |
quick_model_type_gui = gr.Radio(label="Model Type", choices=["None", "Auto", "Animagine", "Pony"], value="Auto", interactive=True)
|
825 |
quick_genre_gui = gr.Radio(label="Genre", choices=["Anime", "Photo"], value="Anime", interactive=True)
|
|
|
830 |
style_selector_gui = gr.Dropdown(label="Style Preset", interactive=True, choices=list(preset_styles.keys()), value="None")
|
831 |
sampler_selector_gui = gr.Dropdown(label="Sampler Quick Settings", interactive=True, choices=list(preset_sampler_setting.keys()), value="None")
|
832 |
optimization_gui = gr.Dropdown(label="Optimization for SDXL", choices=list(optimization_list.keys()), value="None", interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
with gr.Group():
|
834 |
+
with gr.Accordion("Prompt from Image", open=False) as menu_from_image:
|
835 |
+
input_image_gui = gr.Image(label="Input image", type="pil", sources=["upload", "clipboard"], height=256)
|
836 |
+
with gr.Accordion(label="Advanced options", open=False):
|
837 |
+
general_threshold_gui = gr.Slider(label="Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.01, interactive=True)
|
838 |
+
character_threshold_gui = gr.Slider(label="Character threshold", minimum=0.0, maximum=1.0, value=0.8, step=0.01, interactive=True)
|
839 |
+
tag_type_gui = gr.Radio(label="Convert tags to", info="danbooru for Animagine, e621 for Pony.", choices=["danbooru", "e621"], value="danbooru")
|
840 |
+
recom_prompt_gui = gr.Radio(label="Insert reccomended prompt", choices=["None", "Animagine", "Pony"], value="None", interactive=True)
|
841 |
+
keep_tags_gui = gr.Radio(label="Remove tags leaving only the following", choices=["body", "dress", "all"], value="all")
|
842 |
+
image_algorithms = gr.CheckboxGroup(["Use WD Tagger"], label="Algorithms", value=["Use WD Tagger"], visible=False)
|
843 |
+
generate_from_image_btn_gui = gr.Button(value="GENERATE TAGS FROM IMAGE")
|
844 |
prompt_gui = gr.Textbox(lines=6, placeholder="1girl, solo, ...", label="Prompt", show_copy_button=True)
|
845 |
with gr.Accordion("Negative prompt, etc.", open=False) as menu_negative:
|
846 |
neg_prompt_gui = gr.Textbox(lines=3, placeholder="lowres, (bad), ...", label="Negative prompt", show_copy_button=True)
|
|
|
852 |
with gr.Row():
|
853 |
character_dbt = gr.Textbox(lines=1, placeholder="kafuu chino, ...", label="Character names")
|
854 |
series_dbt = gr.Textbox(lines=1, placeholder="Is the order a rabbit?, ...", label="Series names")
|
855 |
+
random_character_gui = gr.Button(value="Random character 🎲", size="sm", variant="secondary")
|
856 |
model_name_dbt = gr.Dropdown(label="Model", choices=list(V2_ALL_MODELS.keys()), value=list(V2_ALL_MODELS.keys())[0], visible=False)
|
857 |
aspect_ratio_dbt = gr.Radio(label="Aspect ratio", choices=list(V2_ASPECT_RATIO_OPTIONS), value="square", visible=False)
|
858 |
length_dbt = gr.Radio(label="Length", choices=list(V2_LENGTH_OPTIONS), value="very_long", visible=False)
|
859 |
identity_dbt = gr.Radio(label="Keep identity", choices=list(V2_IDENTITY_OPTIONS), value="lax", visible=False)
|
860 |
ban_tags_dbt = gr.Textbox(label="Ban tags", placeholder="alternate costumen, ...", value="futanari, censored, furry, furrification", visible=False)
|
|
|
861 |
copy_button_dbt = gr.Button(value="Copy to clipboard", visible=False)
|
|
|
862 |
rating_dbt = gr.Radio(label="Rating", choices=list(V2_RATING_OPTIONS), value="sfw")
|
863 |
+
generate_db_random_button = gr.Button(value="EXTEND PROMPT 🎲")
|
864 |
+
with gr.Row():
|
865 |
+
set_random_seed = gr.Button(value="Seed 🎲", size="sm")
|
866 |
+
set_params_gui = gr.Button(value="Params ↙️", size="sm")
|
867 |
+
clear_prompt_gui = gr.Button(value="Clear 🗑️", size="sm")
|
868 |
+
|
869 |
generate_button = gr.Button(value="GENERATE IMAGE", size="lg", variant="primary")
|
870 |
|
871 |
model_name_gui.change(
|
|
|
1607 |
).success(
|
1608 |
insert_recom_prompt, [prompt_gui, neg_prompt_gui, recom_prompt_gui], [prompt_gui, neg_prompt_gui], queue=False,
|
1609 |
)
|
|
|
|
|
|
|
1610 |
|
1611 |
prompt_type_button.click(convert_danbooru_to_e621_prompt, [prompt_gui, prompt_type_gui], [prompt_gui], queue=False)
|
1612 |
random_character_gui.click(select_random_character, [series_dbt, character_dbt], [series_dbt, character_dbt], queue=False)
|
1613 |
generate_db_random_button.click(
|
1614 |
+
v2_random_prompt,
|
1615 |
+
[prompt_gui, series_dbt, character_dbt,
|
1616 |
+
rating_dbt, aspect_ratio_dbt, length_dbt, identity_dbt, ban_tags_dbt, model_name_dbt],
|
1617 |
+
[prompt_gui, series_dbt, character_dbt],
|
1618 |
+
).success(
|
1619 |
+
convert_danbooru_to_e621_prompt, [prompt_gui, tag_type_gui], [prompt_gui], queue=False,
|
1620 |
)
|
1621 |
|
1622 |
translate_prompt_button.click(translate_prompt, [prompt_gui], [prompt_gui], queue=False)
|
|
|
1744 |
).success(save_gallery_images, [result_images], [result_images, result_images_files, result_images_files], queue=False)
|
1745 |
|
1746 |
with gr.Tab("Danbooru Tags Transformer with WD Tagger", render=True):
|
|
|
1747 |
with gr.Column(scale=2):
|
1748 |
with gr.Group():
|
1749 |
input_image = gr.Image(label="Input image", type="pil", sources=["upload", "clipboard"], height=256)
|
|
|
1752 |
character_threshold = gr.Slider(label="Character threshold", minimum=0.0, maximum=1.0, value=0.8, step=0.01, interactive=True)
|
1753 |
input_tag_type = gr.Radio(label="Convert tags to", info="danbooru for Animagine, e621 for Pony.", choices=["danbooru", "e621"], value="danbooru")
|
1754 |
recom_prompt = gr.Radio(label="Insert reccomended prompt", choices=["None", "Animagine", "Pony"], value="None", interactive=True)
|
1755 |
+
image_algorithms = gr.CheckboxGroup(["Use WD Tagger"], label="Algorithms", value=["Use WD Tagger"], visible=False)
|
1756 |
keep_tags = gr.Radio(label="Remove tags leaving only the following", choices=["body", "dress", "all"], value="all")
|
1757 |
generate_from_image_btn = gr.Button(value="GENERATE TAGS FROM IMAGE", size="lg", variant="primary")
|
1758 |
|
1759 |
with gr.Group():
|
1760 |
+
with gr.Row():
|
1761 |
+
input_character = gr.Textbox(label="Character tags", placeholder="hatsune miku")
|
1762 |
+
input_copyright = gr.Textbox(label="Copyright tags", placeholder="vocaloid")
|
1763 |
+
pick_random_character = gr.Button(value="Random character 🎲", size="sm")
|
1764 |
input_general = gr.TextArea(label="General tags", lines=4, placeholder="1girl, ...", value="")
|
1765 |
input_tags_to_copy = gr.Textbox(value="", visible=False)
|
1766 |
+
with gr.Row():
|
1767 |
+
copy_input_btn = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
|
1768 |
+
copy_prompt_btn_input = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
|
1769 |
translate_input_prompt_button = gr.Button(value="Translate prompt to English", size="sm", variant="secondary")
|
1770 |
tag_type = gr.Radio(label="Output tag conversion", info="danbooru for Animagine, e621 for Pony.", choices=["danbooru", "e621"], value="e621", visible=False)
|
1771 |
input_rating = gr.Radio(label="Rating", choices=list(V2_RATING_OPTIONS), value="explicit")
|
|
|
1783 |
|
1784 |
with gr.Group():
|
1785 |
output_text = gr.TextArea(label="Output tags", interactive=False, show_copy_button=True)
|
1786 |
+
with gr.Row():
|
1787 |
+
copy_btn = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
|
1788 |
+
copy_prompt_btn = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
|
1789 |
|
1790 |
with gr.Group():
|
1791 |
output_text_pony = gr.TextArea(label="Output tags (Pony e621 style)", interactive=False, show_copy_button=True)
|
1792 |
+
with gr.Row():
|
1793 |
+
copy_btn_pony = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
|
1794 |
+
copy_prompt_btn_pony = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
|
1795 |
|
1796 |
description_ui()
|
1797 |
|
|
|
|
|
|
|
1798 |
translate_input_prompt_button.click(translate_prompt, inputs=[input_general], outputs=[input_general], queue=False)
|
1799 |
translate_input_prompt_button.click(translate_prompt, inputs=[input_character], outputs=[input_character], queue=False)
|
1800 |
translate_input_prompt_button.click(translate_prompt, inputs=[input_copyright], outputs=[input_copyright], queue=False)
|
|
|
1809 |
convert_danbooru_to_e621_prompt, inputs=[input_general, input_tag_type], outputs=[input_general], queue=False,
|
1810 |
).success(
|
1811 |
insert_recom_prompt, inputs=[input_general, dummy_np, recom_prompt], outputs=[input_general, dummy_np], queue=False,
|
1812 |
+
).success(lambda: gr.update(interactive=True), None, [copy_prompt_btn_input], queue=False)
|
1813 |
copy_input_btn.click(compose_prompt_to_copy, inputs=[input_character, input_copyright, input_general], outputs=[input_tags_to_copy])\
|
1814 |
.success(gradio_copy_text, inputs=[input_tags_to_copy], js=COPY_ACTION_JS)
|
1815 |
+
copy_prompt_btn_input.click(compose_prompt_to_copy, inputs=[input_character, input_copyright, input_general], outputs=[input_tags_to_copy])\
|
1816 |
+
.success(gradio_copy_prompt, inputs=[input_tags_to_copy], outputs=[prompt_gui])
|
1817 |
+
|
1818 |
pick_random_character.click(select_random_character, [input_copyright, input_character], [input_copyright, input_character])
|
1819 |
|
1820 |
generate_btn.click(
|
1821 |
+
v2_upsampling_prompt,
|
1822 |
+
[model_name, input_copyright, input_character, input_general,
|
1823 |
+
input_rating, input_aspect_ratio, input_length, input_identity, input_ban_tags],
|
1824 |
+
[output_text],
|
1825 |
).success(
|
1826 |
convert_danbooru_to_e621_prompt, inputs=[output_text, tag_type], outputs=[output_text_pony], queue=False,
|
1827 |
).success(
|
1828 |
insert_recom_prompt, inputs=[output_text, dummy_np, recom_animagine], outputs=[output_text, dummy_np], queue=False,
|
1829 |
).success(
|
1830 |
insert_recom_prompt, inputs=[output_text_pony, dummy_np, recom_pony], outputs=[output_text_pony, dummy_np], queue=False,
|
1831 |
+
).success(lambda: (gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)),
|
1832 |
+
None, [copy_btn, copy_btn_pony, copy_prompt_btn, copy_prompt_btn_pony], queue=False)
|
1833 |
copy_btn.click(gradio_copy_text, inputs=[output_text], js=COPY_ACTION_JS)
|
1834 |
copy_btn_pony.click(gradio_copy_text, inputs=[output_text_pony], js=COPY_ACTION_JS)
|
1835 |
+
copy_prompt_btn.click(gradio_copy_prompt, inputs=[output_text], outputs=[prompt_gui])
|
1836 |
+
copy_prompt_btn_pony.click(gradio_copy_prompt, inputs=[output_text_pony], outputs=[prompt_gui])
|
1837 |
|
1838 |
gr.DuplicateButton(value="Duplicate Space for private use (This demo does not work on CPU. Requires Space with GPU available.)", elem_id="duplicate-button", visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1")
|
1839 |
|
env.py
CHANGED
@@ -58,6 +58,8 @@ download_vae_list = [
|
|
58 |
'https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl.vae.safetensors?download=true',
|
59 |
'https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-c-1.1-b-0.5.safetensors?download=true',
|
60 |
'https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-blessed.safetensors?download=true',
|
|
|
|
|
61 |
]
|
62 |
|
63 |
# - **Download LoRAs**
|
|
|
58 |
'https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl.vae.safetensors?download=true',
|
59 |
'https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-c-1.1-b-0.5.safetensors?download=true',
|
60 |
'https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-blessed.safetensors?download=true',
|
61 |
+
"https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt",
|
62 |
+
"https://huggingface.co/stabilityai/sd-vae-ft-ema-original/resolve/main/vae-ft-ema-560000-ema-pruned.ckpt",
|
63 |
]
|
64 |
|
65 |
# - **Download LoRAs**
|
utils.py
CHANGED
@@ -43,3 +43,8 @@ COPY_ACTION_JS = """\
|
|
43 |
navigator.clipboard.writeText(inputs);
|
44 |
}
|
45 |
}"""
|
|
|
|
|
|
|
|
|
|
|
|
43 |
navigator.clipboard.writeText(inputs);
|
44 |
}
|
45 |
}"""
|
46 |
+
|
47 |
+
|
48 |
+
def gradio_copy_prompt(prompt: str):
|
49 |
+
gr.Info("Copied!")
|
50 |
+
return prompt
|
v2.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import time
|
2 |
-
import os
|
3 |
import torch
|
4 |
from typing import Callable
|
|
|
5 |
|
6 |
from dartrs.v2 import (
|
7 |
V2Model,
|
@@ -20,9 +20,12 @@ from dartrs.utils import get_generation_config
|
|
20 |
import gradio as gr
|
21 |
from gradio.components import Component
|
22 |
|
23 |
-
from output import UpsamplingOutput
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
V2_ALL_MODELS = {
|
28 |
"dart-v2-moe-sft": {
|
@@ -40,8 +43,8 @@ V2_ALL_MODELS = {
|
|
40 |
|
41 |
def prepare_models(model_config: dict):
|
42 |
model_name = model_config["repo"]
|
43 |
-
tokenizer = DartTokenizer.from_pretrained(model_name
|
44 |
-
model = model_config["class"].from_pretrained(model_name
|
45 |
|
46 |
return {
|
47 |
"tokenizer": tokenizer,
|
@@ -202,3 +205,56 @@ class V2UI:
|
|
202 |
elapsed_time=elapsed_time,
|
203 |
)
|
204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import time
|
|
|
2 |
import torch
|
3 |
from typing import Callable
|
4 |
+
from pathlib import Path
|
5 |
|
6 |
from dartrs.v2 import (
|
7 |
V2Model,
|
|
|
20 |
import gradio as gr
|
21 |
from gradio.components import Component
|
22 |
|
|
|
23 |
|
24 |
+
try:
|
25 |
+
from output import UpsamplingOutput
|
26 |
+
except:
|
27 |
+
from .output import UpsamplingOutput
|
28 |
+
|
29 |
|
30 |
V2_ALL_MODELS = {
|
31 |
"dart-v2-moe-sft": {
|
|
|
43 |
|
44 |
def prepare_models(model_config: dict):
|
45 |
model_name = model_config["repo"]
|
46 |
+
tokenizer = DartTokenizer.from_pretrained(model_name)
|
47 |
+
model = model_config["class"].from_pretrained(model_name)
|
48 |
|
49 |
return {
|
50 |
"tokenizer": tokenizer,
|
|
|
205 |
elapsed_time=elapsed_time,
|
206 |
)
|
207 |
|
208 |
+
|
209 |
+
def parse_upsampling_output_simple(upsampler: UpsamplingOutput):
|
210 |
+
return gen_prompt_text(upsampler)
|
211 |
+
|
212 |
+
|
213 |
+
v2 = V2UI()
|
214 |
+
|
215 |
+
|
216 |
+
def v2_upsampling_prompt(model: str = "dart-v2-moe-sft", copyright: str = "", character: str = "",
|
217 |
+
general_tags: str = "", rating: str = "nsfw", aspect_ratio: str = "square",
|
218 |
+
length: str = "very_long", identity: str = "lax", ban_tags: str = "censored"):
|
219 |
+
raw_prompt = parse_upsampling_output_simple(v2.on_generate(model, copyright, character, general_tags,
|
220 |
+
rating, aspect_ratio, length, identity, ban_tags))
|
221 |
+
return raw_prompt
|
222 |
+
|
223 |
+
|
224 |
+
def load_dict_from_csv(filename):
|
225 |
+
dict = {}
|
226 |
+
if not Path(filename).exists():
|
227 |
+
if Path('./tagger/', filename).exists(): filename = str(Path('./tagger/', filename))
|
228 |
+
else: return dict
|
229 |
+
try:
|
230 |
+
with open(filename, 'r', encoding="utf-8") as f:
|
231 |
+
lines = f.readlines()
|
232 |
+
except Exception:
|
233 |
+
print(f"Failed to open dictionary file: {filename}")
|
234 |
+
return dict
|
235 |
+
for line in lines:
|
236 |
+
parts = line.strip().split(',')
|
237 |
+
dict[parts[0]] = parts[1]
|
238 |
+
return dict
|
239 |
+
|
240 |
+
|
241 |
+
anime_series_dict = load_dict_from_csv('character_series_dict.csv')
|
242 |
+
|
243 |
+
|
244 |
+
def select_random_character(series: str, character: str):
|
245 |
+
from random import seed, randrange
|
246 |
+
seed()
|
247 |
+
character_list = list(anime_series_dict.keys())
|
248 |
+
character = character_list[randrange(len(character_list) - 1)]
|
249 |
+
series = anime_series_dict.get(character.split(",")[0].strip(), "")
|
250 |
+
return series, character
|
251 |
+
|
252 |
+
|
253 |
+
def v2_random_prompt(general_tags: str = "", copyright: str = "", character: str = "", rating: str = "nsfw",
|
254 |
+
aspect_ratio: str = "square", length: str = "very_long", identity: str = "lax",
|
255 |
+
ban_tags: str = "censored", model: str = "dart-v2-moe-sft"):
|
256 |
+
if copyright == "" and character == "":
|
257 |
+
copyright, character = select_random_character("", "")
|
258 |
+
raw_prompt = v2_upsampling_prompt(model, copyright, character, general_tags, rating,
|
259 |
+
aspect_ratio, length, identity, ban_tags)
|
260 |
+
return raw_prompt, copyright, character
|