Spaces:
Paused
Paused
Batch count functionality + stop btn
Browse files
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,
|
@@ -169,18 +171,37 @@ def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, he
|
|
169 |
"cfg_scale": cfg_scale,
|
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 +213,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",
|
@@ -245,8 +275,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,7 +316,7 @@ 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)
|
@@ -300,8 +331,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 +354,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)
|
@@ -369,12 +401,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,
|
|
|
171 |
"cfg_scale": cfg_scale,
|
172 |
"width": width,
|
173 |
"height": height,
|
174 |
+
"seed": seed,
|
175 |
+
"upscale": True
|
176 |
+
}
|
177 |
+
|
178 |
+
total_images = []
|
179 |
+
threads = []
|
180 |
+
|
181 |
+
def generate_one_image():
|
182 |
+
result = prodia_client.generate(data)
|
183 |
+
job = prodia_client.wait(result)
|
184 |
+
total_images.append(job['imageUrl'])
|
185 |
+
|
186 |
+
for x in range(batch_count):
|
187 |
+
t = Thread(target=generate_one_image)
|
188 |
+
threads.append(t)
|
189 |
+
t.start()
|
190 |
|
191 |
+
for t in threads:
|
192 |
+
t.join()
|
193 |
|
194 |
new_images_list = [img['name'] for img in gallery]
|
|
|
195 |
|
196 |
+
for image in total_images:
|
197 |
+
new_images_list.insert(0, image)
|
198 |
|
199 |
+
return {image_output: total_images, gallery_obj: new_images_list}
|
200 |
+
|
201 |
+
|
202 |
+
def img2img(input_image, denoising, prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed,
|
203 |
+
batch_count, gallery):
|
204 |
+
data = {
|
205 |
"imageData": image_to_base64(input_image),
|
206 |
"denoising_strength": denoising,
|
207 |
"prompt": prompt,
|
|
|
213 |
"width": width,
|
214 |
"height": height,
|
215 |
"seed": seed
|
216 |
+
}
|
217 |
|
218 |
+
total_images = []
|
219 |
+
threads = []
|
220 |
|
221 |
+
def generate_one_image():
|
222 |
+
result = prodia_client.transform(data)
|
223 |
+
job = prodia_client.wait(result)
|
224 |
+
total_images.append(job['imageUrl'])
|
225 |
|
226 |
+
for x in range(batch_count):
|
227 |
+
t = Thread(target=generate_one_image)
|
228 |
+
threads.append(t)
|
229 |
+
t.start()
|
230 |
|
231 |
+
for t in threads:
|
232 |
+
t.join()
|
233 |
|
234 |
+
new_images_list = [img['name'] for img in gallery]
|
235 |
+
|
236 |
+
for image in total_images:
|
237 |
+
new_images_list.insert(0, image)
|
238 |
+
|
239 |
+
return {i2i_image_output: total_images, gallery_obj: new_images_list}
|
240 |
|
241 |
samplers = [
|
242 |
"Euler",
|
|
|
275 |
with gr.Column(scale=6, min_width=600):
|
276 |
prompt = gr.Textbox("space warrior, beautiful, female, ultrarealistic, soft lighting, 8k", placeholder="Prompt", show_label=False, lines=3)
|
277 |
negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=False, lines=3, value="3d, cartoon, anime, (deformed eyes, nose, ears, nose), bad anatomy, ugly")
|
278 |
+
with gr.Row(scale=6):
|
279 |
+
text_button = gr.Button("Generate", variant='primary')
|
280 |
+
stop_btn = gr.Button("Cancel", elem_id="cancel")
|
281 |
|
282 |
with gr.Row():
|
283 |
with gr.Column(scale=3):
|
|
|
316 |
|
317 |
with gr.Column(scale=1):
|
318 |
batch_size = gr.Slider(label="Batch Size", maximum=1, value=1)
|
319 |
+
batch_count = gr.Slider(label="Batch Count", minimum=1, maximum=100, value=1, step=1)
|
320 |
|
321 |
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
|
322 |
seed = gr.Number(label="Seed", value=-1)
|
|
|
331 |
with gr.Column(scale=6, min_width=600):
|
332 |
i2i_prompt = gr.Textbox("space warrior, beautiful, female, ultrarealistic, soft lighting, 8k", placeholder="Prompt", show_label=False, lines=3)
|
333 |
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")
|
334 |
+
with gr.Row(scale=6):
|
335 |
i2i_text_button = gr.Button("Generate", variant='primary', elem_id="generate")
|
336 |
+
i2i_stop_btn = gr.Button("Cancel", elem_id="cancel")
|
337 |
|
338 |
with gr.Row():
|
339 |
with gr.Column(scale=3):
|
|
|
354 |
|
355 |
with gr.Column(scale=1):
|
356 |
i2i_batch_size = gr.Slider(label="Batch Size", maximum=1, value=1)
|
357 |
+
i2i_batch_count = gr.Slider(label="Batch Count", minimum=1, maximum=100, value=1, step=1)
|
358 |
|
359 |
i2i_cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
|
360 |
i2i_denoising = gr.Slider(label="Denoising Strength", minimum=0, maximum=1, value=0.7, step=0.1)
|
|
|
401 |
with gr.Tab("Gallery"):
|
402 |
gallery_obj = gr.Gallery(height=500, columns=4)
|
403 |
|
404 |
+
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])
|
405 |
+
stop_btn.click(fn=None, outputs=None, cancels=[t2i])
|
406 |
+
|
407 |
image_input.upload(get_exif_data, inputs=[image_input], outputs=exif_output)
|
408 |
send_to_txt2img_btn.click(send_to_txt2img, inputs=[image_input], outputs=[tabs, prompt, negative_prompt, steps, seed,
|
409 |
model, sampler, width, height, cfg_scale])
|
|
|
410 |
|
411 |
+
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])
|
412 |
+
i2i_stop_btn.click(fn=None, outputs=None, cancels=[i2i_event])
|
413 |
|
414 |
demo.queue(concurrency_count=32)
|
415 |
demo.launch()
|