Upload 3 files
Browse files- app.py +140 -4
- model.py +81 -0
- requirements.txt +7 -0
app.py
CHANGED
@@ -1,6 +1,142 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from model import models
|
3 |
+
from multit2i import (load_models, infer_fn, infer_rand_fn, save_gallery,
|
4 |
+
change_model, warm_model, get_model_info_md, loaded_models,
|
5 |
+
get_positive_prefix, get_positive_suffix, get_negative_prefix, get_negative_suffix,
|
6 |
+
get_recom_prompt_type, set_recom_prompt_preset, get_tag_type, randomize_seed, translate_to_en)
|
7 |
|
8 |
+
max_images = 8
|
9 |
+
MAX_SEED = 2**32-1
|
10 |
+
load_models(models)
|
11 |
+
|
12 |
+
css = """
|
13 |
+
.model_info { text-align: center; }
|
14 |
+
.output { width=112px; height=112px; max_width=112px; max_height=112px; !important; }
|
15 |
+
.gallery { min_width=512px; min_height=512px; max_height=1024px; !important; }
|
16 |
+
"""
|
17 |
+
|
18 |
+
with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
|
19 |
+
with gr.Tab("Image Generator"):
|
20 |
+
with gr.Row():
|
21 |
+
with gr.Column(scale=10):
|
22 |
+
with gr.Group():
|
23 |
+
prompt = gr.Text(label="Prompt", lines=2, max_lines=8, placeholder="1girl, solo, ...", show_copy_button=True)
|
24 |
+
with gr.Accordion("Advanced options", open=False):
|
25 |
+
neg_prompt = gr.Text(label="Negative Prompt", lines=1, max_lines=8, placeholder="")
|
26 |
+
with gr.Row():
|
27 |
+
width = gr.Slider(label="Width", info="If 0, the default value is used.", maximum=1216, step=32, value=0)
|
28 |
+
height = gr.Slider(label="Height", info="If 0, the default value is used.", maximum=1216, step=32, value=0)
|
29 |
+
steps = gr.Slider(label="Number of inference steps", info="If 0, the default value is used.", maximum=100, step=1, value=0)
|
30 |
+
with gr.Row():
|
31 |
+
cfg = gr.Slider(label="Guidance scale", info="If 0, the default value is used.", maximum=30.0, step=0.1, value=0)
|
32 |
+
seed = gr.Slider(label="Seed", info="Randomize Seed if -1.", minimum=-1, maximum=MAX_SEED, step=1, value=-1)
|
33 |
+
seed_rand = gr.Button("Randomize Seed 🎲", size="sm", variant="secondary")
|
34 |
+
recom_prompt_preset = gr.Radio(label="Set Presets", choices=get_recom_prompt_type(), value="Common")
|
35 |
+
with gr.Row():
|
36 |
+
positive_prefix = gr.CheckboxGroup(label="Use Positive Prefix", choices=get_positive_prefix(), value=[])
|
37 |
+
positive_suffix = gr.CheckboxGroup(label="Use Positive Suffix", choices=get_positive_suffix(), value=["Common"])
|
38 |
+
negative_prefix = gr.CheckboxGroup(label="Use Negative Prefix", choices=get_negative_prefix(), value=[])
|
39 |
+
negative_suffix = gr.CheckboxGroup(label="Use Negative Suffix", choices=get_negative_suffix(), value=["Common"])
|
40 |
+
with gr.Row():
|
41 |
+
image_num = gr.Slider(label="Number of images", minimum=1, maximum=max_images, value=1, step=1, interactive=True, scale=2)
|
42 |
+
trans_prompt = gr.Button(value="Translate 📝", variant="secondary", size="sm", scale=2)
|
43 |
+
clear_prompt = gr.Button(value="Clear 🗑️", variant="secondary", size="sm", scale=1)
|
44 |
+
with gr.Row():
|
45 |
+
run_button = gr.Button("Generate Image", variant="primary", scale=8)
|
46 |
+
random_button = gr.Button("Random Model 🎲", variant="secondary", scale=3)
|
47 |
+
stop_button = gr.Button('Stop', interactive=False, variant="stop", scale=1)
|
48 |
+
|
49 |
+
with gr.Group():
|
50 |
+
model_name = gr.Dropdown(label="Select Model", choices=list(loaded_models.keys()), value=list(loaded_models.keys())[0], allow_custom_value=True)
|
51 |
+
model_info = gr.Markdown(value=get_model_info_md(list(loaded_models.keys())[0]), elem_classes="model_info")
|
52 |
+
with gr.Column(scale=10):
|
53 |
+
with gr.Group():
|
54 |
+
with gr.Row():
|
55 |
+
output = [gr.Image(label='', elem_classes="output", type="filepath", format="png",
|
56 |
+
show_download_button=True, show_share_button=False, show_label=False,
|
57 |
+
interactive=False, min_width=80, visible=True, width=112, height=112) for _ in range(max_images)]
|
58 |
+
with gr.Group():
|
59 |
+
results = gr.Gallery(label="Gallery", elem_classes="gallery", interactive=False, show_download_button=True, show_share_button=False,
|
60 |
+
container=True, format="png", object_fit="cover", columns=2, rows=2)
|
61 |
+
image_files = gr.Files(label="Download", interactive=False)
|
62 |
+
clear_results = gr.Button("Clear Gallery / Download 🗑️", variant="secondary")
|
63 |
+
with gr.Column():
|
64 |
+
examples = gr.Examples(
|
65 |
+
examples = [
|
66 |
+
["souryuu asuka langley, 1girl, neon genesis evangelion, plugsuit, pilot suit, red bodysuit, sitting, crossing legs, black eye patch, cat hat, throne, symmetrical, looking down, from bottom, looking at viewer, outdoors"],
|
67 |
+
["sailor moon, magical girl transformation, sparkles and ribbons, soft pastel colors, crescent moon motif, starry night sky background, shoujo manga style"],
|
68 |
+
["kafuu chino, 1girl, solo"],
|
69 |
+
["1girl"],
|
70 |
+
["beautiful sunset"],
|
71 |
+
],
|
72 |
+
inputs=[prompt],
|
73 |
+
cache_examples=False,
|
74 |
+
)
|
75 |
+
with gr.Tab("PNG Info"):
|
76 |
+
def extract_exif_data(image):
|
77 |
+
if image is None: return ""
|
78 |
+
try:
|
79 |
+
metadata_keys = ['parameters', 'metadata', 'prompt', 'Comment']
|
80 |
+
for key in metadata_keys:
|
81 |
+
if key in image.info:
|
82 |
+
return image.info[key]
|
83 |
+
return str(image.info)
|
84 |
+
except Exception as e:
|
85 |
+
return f"Error extracting metadata: {str(e)}"
|
86 |
+
with gr.Row():
|
87 |
+
with gr.Column():
|
88 |
+
image_metadata = gr.Image(label="Image with metadata", type="pil", sources=["upload"])
|
89 |
+
with gr.Column():
|
90 |
+
result_metadata = gr.Textbox(label="Metadata", show_label=True, show_copy_button=True, interactive=False, container=True, max_lines=99)
|
91 |
+
|
92 |
+
image_metadata.change(
|
93 |
+
fn=extract_exif_data,
|
94 |
+
inputs=[image_metadata],
|
95 |
+
outputs=[result_metadata],
|
96 |
+
)
|
97 |
+
gr.Markdown(
|
98 |
+
f"""This demo was created in reference to the following demos.<br>
|
99 |
+
[Nymbo/Flood](https://huggingface.co/spaces/Nymbo/Flood),
|
100 |
+
[Yntec/ToyWorldXL](https://huggingface.co/spaces/Yntec/ToyWorldXL),
|
101 |
+
[Yntec/Diffusion80XX](https://huggingface.co/spaces/Yntec/Diffusion80XX).
|
102 |
+
"""
|
103 |
+
)
|
104 |
+
gr.DuplicateButton(value="Duplicate Space")
|
105 |
+
gr.Markdown(f"Just a few edits to *model.py* are all it takes to complete your own collection.")
|
106 |
+
|
107 |
+
gr.on(triggers=[run_button.click, prompt.submit, random_button.click], fn=lambda: gr.update(interactive=True), inputs=None, outputs=stop_button, show_api=False)
|
108 |
+
model_name.change(change_model, [model_name], [model_info], queue=True, show_api=True)\
|
109 |
+
.success(warm_model, [model_name], None, queue=True, show_api=True)
|
110 |
+
for i, o in enumerate(output):
|
111 |
+
img_i = gr.Number(i, visible=False)
|
112 |
+
image_num.change(lambda i, n: gr.update(visible = (i < n)), [img_i, image_num], o, show_api=True)
|
113 |
+
gen_event = gr.on(triggers=[run_button.click, prompt.submit],
|
114 |
+
fn=lambda i, n, m, t1, t2, n1, n2, n3, n4, n5, l1, l2, l3, l4: infer_fn(m, t1, t2, n1, n2, n3, n4, n5, l1, l2, l3, l4) if (i < n) else None,
|
115 |
+
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
116 |
+
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
117 |
+
outputs=[o], queue=True, show_api=False) # Be sure to delete ", queue=False" when activating the stop button
|
118 |
+
gen_event2 = gr.on(triggers=[random_button.click],
|
119 |
+
fn=lambda i, n, m, t1, t2, n1, n2, n3, n4, n5, l1, l2, l3, l4: infer_rand_fn(m, t1, t2, n1, n2, n3, n4, n5, l1, l2, l3, l4) if (i < n) else None,
|
120 |
+
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
121 |
+
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
122 |
+
outputs=[o], queue=True, show_api=False) # Be sure to delete ", queue=False" when activating the stop button
|
123 |
+
o.change(save_gallery, [o, results], [results, image_files], show_api=False)
|
124 |
+
stop_button.click(lambda: gr.update(interactive=False), None, stop_button, cancels=[gen_event, gen_event2], show_api=False)
|
125 |
+
|
126 |
+
clear_prompt.click(lambda: (None, None), None, [prompt, neg_prompt], queue=True, show_api=True)
|
127 |
+
clear_results.click(lambda: (None, None), None, [results, image_files], queue=True, show_api=True)
|
128 |
+
recom_prompt_preset.change(set_recom_prompt_preset, [recom_prompt_preset],
|
129 |
+
[positive_prefix, positive_suffix, negative_prefix, negative_suffix], queue=True, show_api=True)
|
130 |
+
seed_rand.click(randomize_seed, None, [seed], queue=True, show_api=True)
|
131 |
+
trans_prompt.click(translate_to_en, [prompt], [prompt], queue=True, show_api=True)\
|
132 |
+
.then(translate_to_en, [neg_prompt], [neg_prompt], queue=True, show_api=True)
|
133 |
+
|
134 |
+
|
135 |
+
|
136 |
+
|
137 |
+
demo.queue(default_concurrency_limit=240, max_size=240)
|
138 |
+
demo.launch(max_threads=400, ssr_mode=True)
|
139 |
+
# https://github.com/gradio-app/gradio/issues/6339
|
140 |
+
|
141 |
+
demo.queue(concurrency_count=50)
|
142 |
+
demo.launch()
|
model.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from multit2i import find_model_list
|
2 |
+
|
3 |
+
models = [
|
4 |
+
'runwayml/stable-diffusion-v1-5',
|
5 |
+
'stabilityai/stable-diffusion-2',
|
6 |
+
'stabilityai/stable-diffusion-3.5-large',
|
7 |
+
'Linaqruf/animagine-xl-2.0',
|
8 |
+
'Meina/MeinaMix_V11',
|
9 |
+
'Yntec/epiCRealismVAE',
|
10 |
+
'digiplay/m3u',
|
11 |
+
'digiplay/FishMix_v1.1',
|
12 |
+
'digiplay/YabaLMixAnimeRealistic_V1.0_VAE',
|
13 |
+
'digiplay/unstableDiffusersYamerMIX_v3',
|
14 |
+
'digiplay/cosfMix_v1',
|
15 |
+
'digiplay/rRealism_v1.0_riiwa',
|
16 |
+
'vcolamatteo/pokemon-text_to_image_lora_1',
|
17 |
+
'stabilityai/stable-diffusion-2',
|
18 |
+
'KBlueLeaf/kohaku-xl-beta5',
|
19 |
+
'calcuis/illustrious',
|
20 |
+
'stabilityai/stable-diffusion-3.5-large-turbo',
|
21 |
+
'stabilityai/stable-diffusion-3.5-large',
|
22 |
+
'black-forest-labs/FLUX.1-dev',
|
23 |
+
'votepurchase/kivotos-xl-2.',
|
24 |
+
'strangerzonehf/Flux-Isometric-3D-LoRA',
|
25 |
+
'prithivMLmods/SD3.5-Large-Anime-LoRA',
|
26 |
+
'Linaqruf/animagine-xl-2.0',
|
27 |
+
'ckpt/kivotos-xl-2.0',
|
28 |
+
'yodayo-ai/clandestine-xl-1.0',
|
29 |
+
'yodayo-ai/kivotos-xl-2.0',
|
30 |
+
'yodayo-ai/holodayo-xl-2.1',
|
31 |
+
'cagliostrolab/animagine-xl-3.1',
|
32 |
+
'votepurchase/ponyDiffusionV6XL',
|
33 |
+
'eienmojiki/Anything-XL',
|
34 |
+
'eienmojiki/Starry-XL-v5.2',
|
35 |
+
"digiplay/MilkyWonderland_v1",
|
36 |
+
'digiplay/majicMIX_sombre_v2',
|
37 |
+
'digiplay/majicMIX_realistic_v7',
|
38 |
+
'digiplay/majicMIX_realistic_v6',
|
39 |
+
'digiplay/2K',
|
40 |
+
'digiplay/2K-VAE',
|
41 |
+
'digiplay/ya3_VAE',
|
42 |
+
'digiplay/ya3p_VAE',
|
43 |
+
'digiplay/pan04',
|
44 |
+
'digiplay/AM-mix1',
|
45 |
+
'digiplay/MRMD_0505',
|
46 |
+
'Yntec/NostalgicLife',
|
47 |
+
'Yntec/Genuine',
|
48 |
+
'Yntec/Abased',
|
49 |
+
'Yntec/CuteFurry',
|
50 |
+
'Yntec/GOLDFish',
|
51 |
+
'Yntec/Isabelia',
|
52 |
+
'Yntec/incha_re_zoro',
|
53 |
+
'Yntec/InsaneM3U',
|
54 |
+
'votepurchase/counterfeitV30_v30',
|
55 |
+
'Meina/MeinaMix_V11',
|
56 |
+
'KBlueLeaf/Kohaku-XL-Epsilon-rev3',
|
57 |
+
'KBlueLeaf/Kohaku-XL-Zeta',
|
58 |
+
'kayfahaarukku/UrangDiffusion-1.4',
|
59 |
+
'Eugeoter/artiwaifu-diffusion-2.0',
|
60 |
+
'Raelina/Rae-Diffusion-XL-V2',
|
61 |
+
'Raelina/Raemu-XL-V4',
|
62 |
+
'FluffyKaeloky/Midnight-Miqu-103B-v1.5',
|
63 |
+
'Sombressoul/Yi-34B-200K-AWQ',
|
64 |
+
'KBlueLeaf/Kohaku-XL-Zeta',
|
65 |
+
'prashanth970/flux-lora-uncensored',
|
66 |
+
'stablediffusionapi/newrealityxl-global-nsfw',
|
67 |
+
'stablediffusionapi/omnigenxl-nsfw-sfw',
|
68 |
+
'stablediffusionapi/hassaku-xl-sfwnsfw',
|
69 |
+
|
70 |
+
]
|
71 |
+
|
72 |
+
#models = find_model_list("Disty0", [], "", "last_modified", 100)
|
73 |
+
|
74 |
+
|
75 |
+
# Examples:
|
76 |
+
#models = ['yodayo-ai/kivotos-xl-2.0', 'yodayo-ai/holodayo-xl-2.1'] # specific models
|
77 |
+
#models = find_model_list("Yntec", [], "", "last_modified", 10) # John6666's latest 20 models
|
78 |
+
#models = find_model_list("John6666", ["anime"], "", "last_modified", 20) # John6666's latest 20 models with 'anime' tag
|
79 |
+
#models = find_model_list("John6666", [], "anime", "last_modified", 20) # John6666's latest 20 models without 'anime' tag
|
80 |
+
#models = find_model_list("", [], "", "last_modified", 20) # latest 20 text-to-image models of huggingface
|
81 |
+
#models = find_model_list("", [], "", "downloads", 20) # monthly most downloaded 20 text-to-image models of huggingface
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
huggingface_hub
|
2 |
+
translatepy
|
3 |
+
torch
|
4 |
+
accelerate
|
5 |
+
diffusers
|
6 |
+
invisible_watermark
|
7 |
+
transformers
|