Spaces:
Runtime error
Runtime error
Commit
·
2af6f8e
1
Parent(s):
94c6aa7
Batch count functionality + stop btn (#15)
Browse files- Batch count functionality + stop btn (0431c0bf08fd114ce64f9d3f7f81eb606fd0d93e)
- fix bugs (b6c16999e6c3a8ac1622887760698e94789ac5ff)
- change gr.Image() -> gr.Gallery() + remove unused kwargs (78f90d933733bbb85aef6dc31bc07300b9309fb3)
- Update app.py (0a5878065347cd545c2e80cdbaf833e1c88a0efd)
Co-authored-by: Zenafey Baenro <zenafey@users.noreply.huggingface.co>
app.py
CHANGED
|
@@ -7,9 +7,11 @@ import base64
|
|
| 7 |
import os
|
| 8 |
from io import BytesIO
|
| 9 |
import PIL
|
|
|
|
| 10 |
from PIL.ExifTags import TAGS
|
| 11 |
import html
|
| 12 |
import re
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
class Prodia:
|
|
@@ -159,8 +161,8 @@ for model_name in model_list:
|
|
| 159 |
name_without_ext = remove_id_and_ext(model_name)
|
| 160 |
model_names[name_without_ext] = model_name
|
| 161 |
|
| 162 |
-
def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed, gallery):
|
| 163 |
-
|
| 164 |
"prompt": prompt,
|
| 165 |
"negative_prompt": negative_prompt,
|
| 166 |
"model": model,
|
|
@@ -170,17 +172,35 @@ def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, he
|
|
| 170 |
"width": width,
|
| 171 |
"height": height,
|
| 172 |
"seed": seed
|
| 173 |
-
}
|
| 174 |
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
new_images_list = [img['name'] for img in gallery]
|
| 178 |
-
new_images_list.insert(0, job["imageUrl"])
|
| 179 |
|
| 180 |
-
|
|
|
|
| 181 |
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
"imageData": image_to_base64(input_image),
|
| 185 |
"denoising_strength": denoising,
|
| 186 |
"prompt": prompt,
|
|
@@ -192,21 +212,30 @@ def img2img(input_image, denoising, prompt, negative_prompt, model, steps, sampl
|
|
| 192 |
"width": width,
|
| 193 |
"height": height,
|
| 194 |
"seed": seed
|
| 195 |
-
}
|
| 196 |
|
| 197 |
-
|
|
|
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
|
|
|
|
|
|
| 201 |
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
| 203 |
|
|
|
|
|
|
|
| 204 |
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
|
|
|
| 210 |
|
| 211 |
samplers = [
|
| 212 |
"Euler",
|
|
@@ -230,7 +259,7 @@ samplers = [
|
|
| 230 |
"PLMS",
|
| 231 |
]
|
| 232 |
|
| 233 |
-
with gr.Blocks(
|
| 234 |
with gr.Row():
|
| 235 |
with gr.Column(scale=6):
|
| 236 |
model = gr.Dropdown(interactive=True,value="absolutereality_v181.safetensors [3d9d4d2b]", show_label=True, label="Stable Diffusion Checkpoint", choices=prodia_client.list_models())
|
|
@@ -245,8 +274,9 @@ with gr.Blocks(css=css) as demo:
|
|
| 245 |
with gr.Column(scale=6, min_width=600):
|
| 246 |
prompt = gr.Textbox("space warrior, beautiful, female, ultrarealistic, soft lighting, 8k", placeholder="Prompt", show_label=False, lines=3)
|
| 247 |
negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=False, lines=3, value="3d, cartoon, anime, (deformed eyes, nose, ears, nose), bad anatomy, ugly")
|
| 248 |
-
with gr.
|
| 249 |
-
text_button = gr.Button("Generate", variant='primary'
|
|
|
|
| 250 |
|
| 251 |
with gr.Row():
|
| 252 |
with gr.Column(scale=3):
|
|
@@ -285,14 +315,14 @@ with gr.Blocks(css=css) as demo:
|
|
| 285 |
|
| 286 |
with gr.Column(scale=1):
|
| 287 |
batch_size = gr.Slider(label="Batch Size", maximum=1, value=1)
|
| 288 |
-
batch_count = gr.Slider(label="Batch Count",
|
| 289 |
|
| 290 |
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
|
| 291 |
seed = gr.Number(label="Seed", value=-1)
|
| 292 |
|
| 293 |
|
| 294 |
with gr.Column(scale=2):
|
| 295 |
-
image_output = gr.
|
| 296 |
|
| 297 |
|
| 298 |
with gr.Tab("img2img", id='i2i'):
|
|
@@ -300,8 +330,9 @@ with gr.Blocks(css=css) as demo:
|
|
| 300 |
with gr.Column(scale=6, min_width=600):
|
| 301 |
i2i_prompt = gr.Textbox("space warrior, beautiful, female, ultrarealistic, soft lighting, 8k", placeholder="Prompt", show_label=False, lines=3)
|
| 302 |
i2i_negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=False, lines=3, value="3d, cartoon, anime, (deformed eyes, nose, ears, nose), bad anatomy, ugly")
|
| 303 |
-
with gr.
|
| 304 |
i2i_text_button = gr.Button("Generate", variant='primary', elem_id="generate")
|
|
|
|
| 305 |
|
| 306 |
with gr.Row():
|
| 307 |
with gr.Column(scale=3):
|
|
@@ -322,7 +353,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 322 |
|
| 323 |
with gr.Column(scale=1):
|
| 324 |
i2i_batch_size = gr.Slider(label="Batch Size", maximum=1, value=1)
|
| 325 |
-
i2i_batch_count = gr.Slider(label="Batch Count",
|
| 326 |
|
| 327 |
i2i_cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
|
| 328 |
i2i_denoising = gr.Slider(label="Denoising Strength", minimum=0, maximum=1, value=0.7, step=0.1)
|
|
@@ -330,7 +361,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 330 |
|
| 331 |
|
| 332 |
with gr.Column(scale=2):
|
| 333 |
-
i2i_image_output = gr.
|
| 334 |
|
| 335 |
|
| 336 |
with gr.Tab("PNG Info"):
|
|
@@ -369,12 +400,15 @@ with gr.Blocks(css=css) as demo:
|
|
| 369 |
with gr.Tab("Gallery"):
|
| 370 |
gallery_obj = gr.Gallery(height=500, columns=4)
|
| 371 |
|
| 372 |
-
text_button.click(txt2img, inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed, gallery_obj], outputs=[image_output, gallery_obj])
|
|
|
|
|
|
|
| 373 |
image_input.upload(get_exif_data, inputs=[image_input], outputs=exif_output)
|
| 374 |
send_to_txt2img_btn.click(send_to_txt2img, inputs=[image_input], outputs=[tabs, prompt, negative_prompt, steps, seed,
|
| 375 |
model, sampler, width, height, cfg_scale])
|
| 376 |
-
i2i_text_button.click(img2img, inputs=[i2i_image_input, i2i_denoising, i2i_prompt, i2i_negative_prompt, model, i2i_steps, i2i_sampler, i2i_cfg_scale, i2i_width, i2i_height, i2i_seed, gallery_obj], outputs=[i2i_image_output, gallery_obj])
|
| 377 |
|
|
|
|
|
|
|
| 378 |
|
| 379 |
demo.queue(concurrency_count=32)
|
| 380 |
demo.launch()
|
|
|
|
| 7 |
import os
|
| 8 |
from io import BytesIO
|
| 9 |
import PIL
|
| 10 |
+
from PIL import Image
|
| 11 |
from PIL.ExifTags import TAGS
|
| 12 |
import html
|
| 13 |
import re
|
| 14 |
+
from threading import Thread
|
| 15 |
|
| 16 |
|
| 17 |
class Prodia:
|
|
|
|
| 161 |
name_without_ext = remove_id_and_ext(model_name)
|
| 162 |
model_names[name_without_ext] = model_name
|
| 163 |
|
| 164 |
+
def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed, batch_count, gallery):
|
| 165 |
+
data = {
|
| 166 |
"prompt": prompt,
|
| 167 |
"negative_prompt": negative_prompt,
|
| 168 |
"model": model,
|
|
|
|
| 172 |
"width": width,
|
| 173 |
"height": height,
|
| 174 |
"seed": seed
|
| 175 |
+
}
|
| 176 |
|
| 177 |
+
total_images = []
|
| 178 |
+
threads = []
|
| 179 |
+
|
| 180 |
+
def generate_one_image():
|
| 181 |
+
result = prodia_client.generate(data)
|
| 182 |
+
job = prodia_client.wait(result)
|
| 183 |
+
total_images.append(job['imageUrl'])
|
| 184 |
+
|
| 185 |
+
for x in range(batch_count):
|
| 186 |
+
t = Thread(target=generate_one_image)
|
| 187 |
+
threads.append(t)
|
| 188 |
+
t.start()
|
| 189 |
+
|
| 190 |
+
for t in threads:
|
| 191 |
+
t.join()
|
| 192 |
|
| 193 |
new_images_list = [img['name'] for img in gallery]
|
|
|
|
| 194 |
|
| 195 |
+
for image in total_images:
|
| 196 |
+
new_images_list.insert(0, image)
|
| 197 |
|
| 198 |
+
return {image_output: total_images, gallery_obj: new_images_list}
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def img2img(input_image, denoising, prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed,
|
| 202 |
+
batch_count, gallery):
|
| 203 |
+
data = {
|
| 204 |
"imageData": image_to_base64(input_image),
|
| 205 |
"denoising_strength": denoising,
|
| 206 |
"prompt": prompt,
|
|
|
|
| 212 |
"width": width,
|
| 213 |
"height": height,
|
| 214 |
"seed": seed
|
| 215 |
+
}
|
| 216 |
|
| 217 |
+
total_images = []
|
| 218 |
+
threads = []
|
| 219 |
|
| 220 |
+
def generate_one_image():
|
| 221 |
+
result = prodia_client.transform(data)
|
| 222 |
+
job = prodia_client.wait(result)
|
| 223 |
+
total_images.append(job['imageUrl'])
|
| 224 |
|
| 225 |
+
for x in range(batch_count):
|
| 226 |
+
t = Thread(target=generate_one_image)
|
| 227 |
+
threads.append(t)
|
| 228 |
+
t.start()
|
| 229 |
|
| 230 |
+
for t in threads:
|
| 231 |
+
t.join()
|
| 232 |
|
| 233 |
+
new_images_list = [img['name'] for img in gallery]
|
| 234 |
+
|
| 235 |
+
for image in total_images:
|
| 236 |
+
new_images_list.insert(0, image)
|
| 237 |
+
|
| 238 |
+
return {i2i_image_output: total_images, gallery_obj: new_images_list}
|
| 239 |
|
| 240 |
samplers = [
|
| 241 |
"Euler",
|
|
|
|
| 259 |
"PLMS",
|
| 260 |
]
|
| 261 |
|
| 262 |
+
with gr.Blocks() as demo:
|
| 263 |
with gr.Row():
|
| 264 |
with gr.Column(scale=6):
|
| 265 |
model = gr.Dropdown(interactive=True,value="absolutereality_v181.safetensors [3d9d4d2b]", show_label=True, label="Stable Diffusion Checkpoint", choices=prodia_client.list_models())
|
|
|
|
| 274 |
with gr.Column(scale=6, min_width=600):
|
| 275 |
prompt = gr.Textbox("space warrior, beautiful, female, ultrarealistic, soft lighting, 8k", placeholder="Prompt", show_label=False, lines=3)
|
| 276 |
negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=False, lines=3, value="3d, cartoon, anime, (deformed eyes, nose, ears, nose), bad anatomy, ugly")
|
| 277 |
+
with gr.Row():
|
| 278 |
+
text_button = gr.Button("Generate", variant='primary')
|
| 279 |
+
stop_btn = gr.Button("Cancel", elem_id="cancel")
|
| 280 |
|
| 281 |
with gr.Row():
|
| 282 |
with gr.Column(scale=3):
|
|
|
|
| 315 |
|
| 316 |
with gr.Column(scale=1):
|
| 317 |
batch_size = gr.Slider(label="Batch Size", maximum=1, value=1)
|
| 318 |
+
batch_count = gr.Slider(label="Batch Count", minimum=1, maximum=4, value=1, step=1)
|
| 319 |
|
| 320 |
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
|
| 321 |
seed = gr.Number(label="Seed", value=-1)
|
| 322 |
|
| 323 |
|
| 324 |
with gr.Column(scale=2):
|
| 325 |
+
image_output = gr.Gallery(value=["https://images.prodia.xyz/8ede1a7c-c0ee-4ded-987d-6ffed35fc477.png"], preview=True)
|
| 326 |
|
| 327 |
|
| 328 |
with gr.Tab("img2img", id='i2i'):
|
|
|
|
| 330 |
with gr.Column(scale=6, min_width=600):
|
| 331 |
i2i_prompt = gr.Textbox("space warrior, beautiful, female, ultrarealistic, soft lighting, 8k", placeholder="Prompt", show_label=False, lines=3)
|
| 332 |
i2i_negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=False, lines=3, value="3d, cartoon, anime, (deformed eyes, nose, ears, nose), bad anatomy, ugly")
|
| 333 |
+
with gr.Row():
|
| 334 |
i2i_text_button = gr.Button("Generate", variant='primary', elem_id="generate")
|
| 335 |
+
i2i_stop_btn = gr.Button("Cancel", elem_id="cancel")
|
| 336 |
|
| 337 |
with gr.Row():
|
| 338 |
with gr.Column(scale=3):
|
|
|
|
| 353 |
|
| 354 |
with gr.Column(scale=1):
|
| 355 |
i2i_batch_size = gr.Slider(label="Batch Size", maximum=1, value=1)
|
| 356 |
+
i2i_batch_count = gr.Slider(label="Batch Count", minimum=1, maximum=100, value=1, step=1)
|
| 357 |
|
| 358 |
i2i_cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
|
| 359 |
i2i_denoising = gr.Slider(label="Denoising Strength", minimum=0, maximum=1, value=0.7, step=0.1)
|
|
|
|
| 361 |
|
| 362 |
|
| 363 |
with gr.Column(scale=2):
|
| 364 |
+
i2i_image_output = gr.Gallery(value=["https://images.prodia.xyz/8ede1a7c-c0ee-4ded-987d-6ffed35fc477.png"], preview=True)
|
| 365 |
|
| 366 |
|
| 367 |
with gr.Tab("PNG Info"):
|
|
|
|
| 400 |
with gr.Tab("Gallery"):
|
| 401 |
gallery_obj = gr.Gallery(height=500, columns=4)
|
| 402 |
|
| 403 |
+
t2i_event = text_button.click(txt2img, inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed, batch_count, gallery_obj], outputs=[image_output, gallery_obj])
|
| 404 |
+
stop_btn.click(fn=None, outputs=None, cancels=[t2i_event])
|
| 405 |
+
|
| 406 |
image_input.upload(get_exif_data, inputs=[image_input], outputs=exif_output)
|
| 407 |
send_to_txt2img_btn.click(send_to_txt2img, inputs=[image_input], outputs=[tabs, prompt, negative_prompt, steps, seed,
|
| 408 |
model, sampler, width, height, cfg_scale])
|
|
|
|
| 409 |
|
| 410 |
+
i2i_event = i2i_text_button.click(img2img, inputs=[i2i_image_input, i2i_denoising, i2i_prompt, i2i_negative_prompt, model, i2i_steps, i2i_sampler, i2i_cfg_scale, i2i_width, i2i_height, i2i_seed, i2i_batch_count, gallery_obj], outputs=[i2i_image_output, gallery_obj])
|
| 411 |
+
i2i_stop_btn.click(fn=None, outputs=None, cancels=[i2i_event])
|
| 412 |
|
| 413 |
demo.queue(concurrency_count=32)
|
| 414 |
demo.launch()
|