Update app.py
Browse files
app.py
CHANGED
|
@@ -84,31 +84,83 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
|
|
| 84 |
container=True, format="png", object_fit="cover", columns=2, rows=2)
|
| 85 |
image_files = gr.Files(label="Download", interactive=False)
|
| 86 |
clear_results = gr.Button("Clear Gallery / Download 🗑️", variant="secondary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
|
|
|
|
|
|
|
|
|
| 91 |
for i, o in enumerate(output):
|
| 92 |
img_i = gr.Number(i, visible=False)
|
| 93 |
-
image_num.change(lambda i, n: gr.update(visible=(i < n)), [img_i, image_num], o)
|
| 94 |
-
gen_event = gr.on(
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
| 106 |
recom_prompt_preset.change(set_recom_prompt_preset, [recom_prompt_preset],
|
| 107 |
-
|
| 108 |
-
seed_rand.click(randomize_seed, None, [seed], queue=True)
|
| 109 |
-
trans_prompt.click(translate_to_en, [prompt], [prompt], queue=True)\
|
| 110 |
-
.then(translate_to_en, [neg_prompt], [neg_prompt], queue=True)
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
-
# Запуск интерфейса
|
| 113 |
demo.queue(default_concurrency_limit=240, max_size=240)
|
| 114 |
demo.launch(max_threads=400, ssr_mode=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
container=True, format="png", object_fit="cover", columns=2, rows=2)
|
| 85 |
image_files = gr.Files(label="Download", interactive=False)
|
| 86 |
clear_results = gr.Button("Clear Gallery / Download 🗑️", variant="secondary")
|
| 87 |
+
with gr.Column():
|
| 88 |
+
examples = gr.Examples(
|
| 89 |
+
examples = [
|
| 90 |
+
["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"],
|
| 91 |
+
["sailor moon, magical girl transformation, sparkles and ribbons, soft pastel colors, crescent moon motif, starry night sky background, shoujo manga style"],
|
| 92 |
+
["kafuu chino, 1girl, solo"],
|
| 93 |
+
["1girl"],
|
| 94 |
+
["beautiful sunset"],
|
| 95 |
+
],
|
| 96 |
+
inputs=[prompt],
|
| 97 |
+
cache_examples=False,
|
| 98 |
+
)
|
| 99 |
+
with gr.Tab("PNG Info"):
|
| 100 |
+
def extract_exif_data(image):
|
| 101 |
+
if image is None: return ""
|
| 102 |
+
try:
|
| 103 |
+
metadata_keys = ['parameters', 'metadata', 'prompt', 'Comment']
|
| 104 |
+
for key in metadata_keys:
|
| 105 |
+
if key in image.info:
|
| 106 |
+
return image.info[key]
|
| 107 |
+
return str(image.info)
|
| 108 |
+
except Exception as e:
|
| 109 |
+
return f"Error extracting metadata: {str(e)}"
|
| 110 |
+
with gr.Row():
|
| 111 |
+
with gr.Column():
|
| 112 |
+
image_metadata = gr.Image(label="Image with metadata", type="pil", sources=["upload"])
|
| 113 |
+
with gr.Column():
|
| 114 |
+
result_metadata = gr.Textbox(label="Metadata", show_label=True, show_copy_button=True, interactive=False, container=True, max_lines=99)
|
| 115 |
|
| 116 |
+
image_metadata.change(
|
| 117 |
+
fn=extract_exif_data,
|
| 118 |
+
inputs=[image_metadata],
|
| 119 |
+
outputs=[result_metadata],
|
| 120 |
+
)
|
| 121 |
+
gr.Markdown(
|
| 122 |
+
f"""This demo was created in reference to the following demos.<br>
|
| 123 |
+
[Nymbo/Flood](https://huggingface.co/spaces/Nymbo/Flood),
|
| 124 |
+
[Yntec/ToyWorldXL](https://huggingface.co/spaces/Yntec/ToyWorldXL),
|
| 125 |
+
[Yntec/Diffusion80XX](https://huggingface.co/spaces/Yntec/Diffusion80XX).
|
| 126 |
+
"""
|
| 127 |
+
)
|
| 128 |
+
gr.DuplicateButton(value="Duplicate Space")
|
| 129 |
+
gr.Markdown(f"Just a few edits to *model.py* are all it takes to complete your own collection.")
|
| 130 |
|
| 131 |
+
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)
|
| 132 |
+
model_name.change(change_model, [model_name], [model_info], queue=True, show_api=True)\
|
| 133 |
+
.success(warm_model, [model_name], None, queue=True, show_api=True)
|
| 134 |
for i, o in enumerate(output):
|
| 135 |
img_i = gr.Number(i, visible=False)
|
| 136 |
+
image_num.change(lambda i, n: gr.update(visible = (i < n)), [img_i, image_num], o, show_api=True)
|
| 137 |
+
gen_event = gr.on(triggers=[run_button.click, prompt.submit],
|
| 138 |
+
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,
|
| 139 |
+
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
| 140 |
+
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
| 141 |
+
outputs=[o], queue=True, show_api=False) # Be sure to delete ", queue=False" when activating the stop button
|
| 142 |
+
gen_event2 = gr.on(triggers=[random_button.click],
|
| 143 |
+
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,
|
| 144 |
+
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
| 145 |
+
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
| 146 |
+
outputs=[o], queue=True, show_api=False) # Be sure to delete ", queue=False" when activating the stop button
|
| 147 |
+
o.change(save_gallery, [o, results], [results, image_files], show_api=False)
|
| 148 |
+
stop_button.click(lambda: gr.update(interactive=False), None, stop_button, cancels=[gen_event, gen_event2], show_api=False)
|
| 149 |
+
|
| 150 |
+
clear_prompt.click(lambda: (None, None), None, [prompt, neg_prompt], queue=True, show_api=True)
|
| 151 |
+
clear_results.click(lambda: (None, None), None, [results, image_files], queue=True, show_api=True)
|
| 152 |
recom_prompt_preset.change(set_recom_prompt_preset, [recom_prompt_preset],
|
| 153 |
+
[positive_prefix, positive_suffix, negative_prefix, negative_suffix], queue=True, show_api=True)
|
| 154 |
+
seed_rand.click(randomize_seed, None, [seed], queue=True, show_api=True)
|
| 155 |
+
trans_prompt.click(translate_to_en, [prompt], [prompt], queue=True, show_api=True)\
|
| 156 |
+
.then(translate_to_en, [neg_prompt], [neg_prompt], queue=True, show_api=True)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
|
| 160 |
|
|
|
|
| 161 |
demo.queue(default_concurrency_limit=240, max_size=240)
|
| 162 |
demo.launch(max_threads=400, ssr_mode=True)
|
| 163 |
+
# https://github.com/gradio-app/gradio/issues/6339
|
| 164 |
+
|
| 165 |
+
demo.queue(concurrency_count=50)
|
| 166 |
+
demo.launch()
|