Update app.py
Browse files
app.py
CHANGED
@@ -92,79 +92,120 @@ def gen_fn(model_str, prompt, width, height):
|
|
92 |
# Функция основного интерфейса
|
93 |
def make_me():
|
94 |
with gr.Row():
|
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 |
-
model_choice1.change(extend_choices, model_choice1, current_models_row1)
|
164 |
-
|
165 |
-
# Обновляем второй ряд
|
166 |
-
model_choice2.change(update_imgbox, model_choice2, output_row2)
|
167 |
-
model_choice2.change(extend_choices, model_choice2, current_models_row2)
|
168 |
|
169 |
with gr.Row():
|
170 |
gr.HTML("")
|
|
|
92 |
# Функция основного интерфейса
|
93 |
def make_me():
|
94 |
with gr.Row():
|
95 |
+
with gr.Column(scale=10):
|
96 |
+
with gr.Group():
|
97 |
+
prompt = gr.Text(label="Prompt", lines=2, max_lines=8, placeholder="1girl, solo, ...", show_copy_button=True)
|
98 |
+
with gr.Accordion("Advanced options", open=False):
|
99 |
+
neg_prompt = gr.Text(label="Negative Prompt", lines=1, max_lines=8, placeholder="")
|
100 |
+
with gr.Row():
|
101 |
+
width = gr.Slider(label="Width", info="If 0, the default value is used.", maximum=1216, step=32, value=0)
|
102 |
+
height = gr.Slider(label="Height", info="If 0, the default value is used.", maximum=1216, step=32, value=0)
|
103 |
+
steps = gr.Slider(label="Number of inference steps", info="If 0, the default value is used.", maximum=100, step=1, value=0)
|
104 |
+
with gr.Row():
|
105 |
+
cfg = gr.Slider(label="Guidance scale", info="If 0, the default value is used.", maximum=30.0, step=0.1, value=0)
|
106 |
+
seed = gr.Slider(label="Seed", info="Randomize Seed if -1.", minimum=-1, maximum=MAX_SEED, step=1, value=-1)
|
107 |
+
seed_rand = gr.Button("Randomize Seed 🎲", size="sm", variant="secondary")
|
108 |
+
recom_prompt_preset = gr.Radio(label="Set Presets", choices=get_recom_prompt_type(), value="Common")
|
109 |
+
with gr.Row():
|
110 |
+
positive_prefix = gr.CheckboxGroup(label="Use Positive Prefix", choices=get_positive_prefix(), value=[])
|
111 |
+
positive_suffix = gr.CheckboxGroup(label="Use Positive Suffix", choices=get_positive_suffix(), value=["Common"])
|
112 |
+
negative_prefix = gr.CheckboxGroup(label="Use Negative Prefix", choices=get_negative_prefix(), value=[])
|
113 |
+
negative_suffix = gr.CheckboxGroup(label="Use Negative Suffix", choices=get_negative_suffix(), value=["Common"])
|
114 |
+
with gr.Row():
|
115 |
+
image_num = gr.Slider(label="Number of images", minimum=1, maximum=max_images, value=1, step=1, interactive=True, scale=2)
|
116 |
+
trans_prompt = gr.Button(value="Translate 📝", variant="secondary", size="sm", scale=2)
|
117 |
+
clear_prompt = gr.Button(value="Clear 🗑️", variant="secondary", size="sm", scale=1)
|
118 |
+
with gr.Row():
|
119 |
+
run_button = gr.Button("Generate Image", variant="primary", scale=8)
|
120 |
+
random_button = gr.Button("Random Model 🎲", variant="secondary", scale=3)
|
121 |
+
stop_button = gr.Button('Stop', interactive=False, variant="stop", scale=1)
|
122 |
+
|
123 |
+
with gr.Group():
|
124 |
+
model_name = gr.Dropdown(label="Select Model", choices=list(loaded_models.keys()), value=list(loaded_models.keys())[0], allow_custom_value=True)
|
125 |
+
model_info = gr.Markdown(value=get_model_info_md(list(loaded_models.keys())[0]), elem_classes="model_info")
|
126 |
+
with gr.Column(scale=10):
|
127 |
+
with gr.Group():
|
128 |
+
with gr.Row():
|
129 |
+
output = [gr.Image(label='', elem_classes="output", type="filepath", format="png",
|
130 |
+
show_download_button=True, show_share_button=False, show_label=False,
|
131 |
+
interactive=False, min_width=80, visible=True, width=112, height=112) for _ in range(max_images)]
|
132 |
+
with gr.Group():
|
133 |
+
results = gr.Gallery(label="Gallery", elem_classes="gallery", interactive=False, show_download_button=True, show_share_button=False,
|
134 |
+
container=True, format="png", object_fit="cover", columns=2, rows=2)
|
135 |
+
image_files = gr.Files(label="Download", interactive=False)
|
136 |
+
clear_results = gr.Button("Clear Gallery / Download 🗑️", variant="secondary")
|
137 |
+
with gr.Column():
|
138 |
+
examples = gr.Examples(
|
139 |
+
examples = [
|
140 |
+
["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"],
|
141 |
+
["sailor moon, magical girl transformation, sparkles and ribbons, soft pastel colors, crescent moon motif, starry night sky background, shoujo manga style"],
|
142 |
+
["kafuu chino, 1girl, solo"],
|
143 |
+
["1girl"],
|
144 |
+
["beautiful sunset"],
|
145 |
+
],
|
146 |
+
inputs=[prompt],
|
147 |
+
cache_examples=False,
|
148 |
)
|
149 |
+
with gr.Tab("PNG Info"):
|
150 |
+
def extract_exif_data(image):
|
151 |
+
if image is None: return ""
|
152 |
+
try:
|
153 |
+
metadata_keys = ['parameters', 'metadata', 'prompt', 'Comment']
|
154 |
+
for key in metadata_keys:
|
155 |
+
if key in image.info:
|
156 |
+
return image.info[key]
|
157 |
+
return str(image.info)
|
158 |
+
except Exception as e:
|
159 |
+
return f"Error extracting metadata: {str(e)}"
|
160 |
+
with gr.Row():
|
161 |
+
with gr.Column():
|
162 |
+
image_metadata = gr.Image(label="Image with metadata", type="pil", sources=["upload"])
|
163 |
+
with gr.Column():
|
164 |
+
result_metadata = gr.Textbox(label="Metadata", show_label=True, show_copy_button=True, interactive=False, container=True, max_lines=99)
|
165 |
+
|
166 |
+
image_metadata.change(
|
167 |
+
fn=extract_exif_data,
|
168 |
+
inputs=[image_metadata],
|
169 |
+
outputs=[result_metadata],
|
170 |
+
)
|
171 |
+
gr.Markdown(
|
172 |
+
f"""This demo was created in reference to the following demos.<br>
|
173 |
+
[Nymbo/Flood](https://huggingface.co/spaces/Nymbo/Flood),
|
174 |
+
[Yntec/ToyWorldXL](https://huggingface.co/spaces/Yntec/ToyWorldXL),
|
175 |
+
[Yntec/Diffusion80XX](https://huggingface.co/spaces/Yntec/Diffusion80XX).
|
176 |
+
"""
|
177 |
+
)
|
178 |
+
gr.DuplicateButton(value="Duplicate Space")
|
179 |
+
gr.Markdown(f"Just a few edits to *model.py* are all it takes to complete your own collection.")
|
180 |
+
|
181 |
+
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)
|
182 |
+
model_name.change(change_model, [model_name], [model_info], queue=True, show_api=True)\
|
183 |
+
.success(warm_model, [model_name], None, queue=True, show_api=True)
|
184 |
+
for i, o in enumerate(output):
|
185 |
+
img_i = gr.Number(i, visible=False)
|
186 |
+
image_num.change(lambda i, n: gr.update(visible = (i < n)), [img_i, image_num], o, show_api=True)
|
187 |
+
gen_event = gr.on(triggers=[run_button.click, prompt.submit],
|
188 |
+
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,
|
189 |
+
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
190 |
+
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
191 |
+
outputs=[o], queue=True, show_api=False) # Be sure to delete ", queue=False" when activating the stop button
|
192 |
+
gen_event2 = gr.on(triggers=[random_button.click],
|
193 |
+
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,
|
194 |
+
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
195 |
+
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
196 |
+
outputs=[o], queue=True, show_api=False) # Be sure to delete ", queue=False" when activating the stop button
|
197 |
+
o.change(save_gallery, [o, results], [results, image_files], show_api=False)
|
198 |
+
stop_button.click(lambda: gr.update(interactive=False), None, stop_button, cancels=[gen_event, gen_event2], show_api=False)
|
199 |
+
|
200 |
+
clear_prompt.click(lambda: (None, None), None, [prompt, neg_prompt], queue=True, show_api=True)
|
201 |
+
clear_results.click(lambda: (None, None), None, [results, image_files], queue=True, show_api=True)
|
202 |
+
recom_prompt_preset.change(set_recom_prompt_preset, [recom_prompt_preset],
|
203 |
+
[positive_prefix, positive_suffix, negative_prefix, negative_suffix], queue=True, show_api=True)
|
204 |
+
seed_rand.click(randomize_seed, None, [seed], queue=True, show_api=True)
|
205 |
+
trans_prompt.click(translate_to_en, [prompt], [prompt], queue=True, show_api=True)\
|
206 |
+
.then(translate_to_en, [neg_prompt], [neg_prompt], queue=True, show_api=True)
|
207 |
+
|
208 |
+
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
with gr.Row():
|
211 |
gr.HTML("")
|