Spaces:
Runtime error
Runtime error
dreamdrop-art
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -74,13 +74,25 @@ class Prodia:
|
|
74 |
response = self._post(f"{self.base}/sd/generate", params)
|
75 |
return response.json()
|
76 |
|
|
|
|
|
|
|
|
|
77 |
def transform(self, params):
|
78 |
response = self._post(f"{self.base}/sd/transform", params)
|
79 |
return response.json()
|
|
|
|
|
|
|
|
|
80 |
|
81 |
def controlnet(self, params):
|
82 |
response = self._post(f"{self.base}/sd/controlnet", params)
|
83 |
return response.json()
|
|
|
|
|
|
|
|
|
84 |
|
85 |
def get_job(self, job_id):
|
86 |
response = self._get(f"{self.base}/job/{job_id}")
|
@@ -98,10 +110,18 @@ class Prodia:
|
|
98 |
def list_models(self):
|
99 |
response = self._get(f"{self.base}/sd/models")
|
100 |
return response.json()
|
|
|
|
|
|
|
|
|
101 |
|
102 |
def list_samplers(self):
|
103 |
response = self._get(f"{self.base}/sd/samplers")
|
104 |
return response.json()
|
|
|
|
|
|
|
|
|
105 |
|
106 |
def _post(self, url, params):
|
107 |
headers = {
|
@@ -207,11 +227,17 @@ def send_to_txt2img(image):
|
|
207 |
prodia_client = Prodia(api_key=os.getenv("PRODIA_API_KEY"))
|
208 |
model_list = prodia_client.list_models()
|
209 |
model_names = {}
|
|
|
|
|
210 |
|
211 |
for model_name in model_list:
|
212 |
name_without_ext = remove_id_and_ext(model_name)
|
213 |
model_names[name_without_ext] = model_name
|
214 |
|
|
|
|
|
|
|
|
|
215 |
|
216 |
def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, upscale, seed, progress=gr.Progress()):
|
217 |
progress(0, desc="Starting")
|
@@ -234,6 +260,25 @@ def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, he
|
|
234 |
progress(0.99, desc="Sending image")
|
235 |
return [job["imageUrl"]], job["imageUrl"]
|
236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
|
238 |
def img2img(input_image, denoising, prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, upscale, seed, progress=gr.Progress()):
|
239 |
progress(0, desc="Starting")
|
@@ -262,6 +307,36 @@ def img2img(input_image, denoising, prompt, negative_prompt, model, steps, sampl
|
|
262 |
time.sleep(0.5)
|
263 |
return [job["imageUrl"]], job["imageUrl"]
|
264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
|
266 |
css = """
|
267 |
#generate {
|
@@ -422,6 +497,99 @@ with gr.Blocks(css=css) as demo:
|
|
422 |
send_to_png.click(send_to_img2img_def, inputs=past_url, outputs=image_input)
|
423 |
send_to_img2img_png.click(send_to_img2img_def, inputs=past_url, outputs=i2i_image_input)
|
424 |
send_to_png_i2i.click(send_to_img2img_def, inputs=i2i_past_url, outputs=image_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
with gr.Tab("HuggingFace Inference"):
|
426 |
with gr.Row():
|
427 |
gr.Markdown("Add your model from HF.co, enter model ID.")
|
|
|
74 |
response = self._post(f"{self.base}/sd/generate", params)
|
75 |
return response.json()
|
76 |
|
77 |
+
def xl_generate(self, params):
|
78 |
+
response = self._post(f"{self.base}/sdxl/generate", params)
|
79 |
+
return response.json()
|
80 |
+
|
81 |
def transform(self, params):
|
82 |
response = self._post(f"{self.base}/sd/transform", params)
|
83 |
return response.json()
|
84 |
+
|
85 |
+
def xl_transform(self, params):
|
86 |
+
response = self._post(f"{self.base}/sdxl/transform", params)
|
87 |
+
return response.json()
|
88 |
|
89 |
def controlnet(self, params):
|
90 |
response = self._post(f"{self.base}/sd/controlnet", params)
|
91 |
return response.json()
|
92 |
+
|
93 |
+
def xl_controlnet(self, params):
|
94 |
+
response = self._post(f"{self.base}/sdxl/controlnet", params)
|
95 |
+
return response.json()
|
96 |
|
97 |
def get_job(self, job_id):
|
98 |
response = self._get(f"{self.base}/job/{job_id}")
|
|
|
110 |
def list_models(self):
|
111 |
response = self._get(f"{self.base}/sd/models")
|
112 |
return response.json()
|
113 |
+
|
114 |
+
def xl_list_models(self):
|
115 |
+
response = self._get(f"{self.base}/sdxl/models")
|
116 |
+
return response.json()
|
117 |
|
118 |
def list_samplers(self):
|
119 |
response = self._get(f"{self.base}/sd/samplers")
|
120 |
return response.json()
|
121 |
+
|
122 |
+
def xl_list_samplers(self):
|
123 |
+
response = self._get(f"{self.base}/sdxl/samplers")
|
124 |
+
return response.json()
|
125 |
|
126 |
def _post(self, url, params):
|
127 |
headers = {
|
|
|
227 |
prodia_client = Prodia(api_key=os.getenv("PRODIA_API_KEY"))
|
228 |
model_list = prodia_client.list_models()
|
229 |
model_names = {}
|
230 |
+
xl_model_list = prodia_client.xl_list_models()
|
231 |
+
xl_model_names = {}
|
232 |
|
233 |
for model_name in model_list:
|
234 |
name_without_ext = remove_id_and_ext(model_name)
|
235 |
model_names[name_without_ext] = model_name
|
236 |
|
237 |
+
for xl_model_name in xl_model_list:
|
238 |
+
xl_name_without_ext = remove_id_and_ext(xl_model_name)
|
239 |
+
xl_model_names[xl_name_without_ext] = xl_model_name
|
240 |
+
|
241 |
|
242 |
def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, upscale, seed, progress=gr.Progress()):
|
243 |
progress(0, desc="Starting")
|
|
|
260 |
progress(0.99, desc="Sending image")
|
261 |
return [job["imageUrl"]], job["imageUrl"]
|
262 |
|
263 |
+
def xl_txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed, progress=gr.Progress()):
|
264 |
+
progress(0, desc="Starting")
|
265 |
+
time.sleep(2.5)
|
266 |
+
progress(0.25, desc="Generating")
|
267 |
+
result = prodia_client.generate({
|
268 |
+
"prompt": prompt,
|
269 |
+
"negative_prompt": negative_prompt,
|
270 |
+
"model": model,
|
271 |
+
"steps": steps,
|
272 |
+
"sampler": sampler,
|
273 |
+
"cfg_scale": cfg_scale,
|
274 |
+
"width": width,
|
275 |
+
"height": height,
|
276 |
+
"seed": seed
|
277 |
+
})
|
278 |
+
progress(0.75, desc="Opening image")
|
279 |
+
job = prodia_client.wait(result)
|
280 |
+
progress(0.99, desc="Sending image")
|
281 |
+
return [job["imageUrl"]], job["imageUrl"]
|
282 |
|
283 |
def img2img(input_image, denoising, prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, upscale, seed, progress=gr.Progress()):
|
284 |
progress(0, desc="Starting")
|
|
|
307 |
time.sleep(0.5)
|
308 |
return [job["imageUrl"]], job["imageUrl"]
|
309 |
|
310 |
+
def xl_img2img(input_image, denoising, prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed, progress=gr.Progress()):
|
311 |
+
progress(0, desc="Starting")
|
312 |
+
time.sleep(1.5)
|
313 |
+
progress(0.10, desc="Uploading input image")
|
314 |
+
time.sleep(1.5)
|
315 |
+
progress(0.25, desc="Generating")
|
316 |
+
result = prodia_client.transform({
|
317 |
+
"imageData": image_to_base64(input_image),
|
318 |
+
"denoising_strength": denoising,
|
319 |
+
"prompt": prompt,
|
320 |
+
"negative_prompt": negative_prompt,
|
321 |
+
"model": model,
|
322 |
+
"steps": steps,
|
323 |
+
"sampler": sampler,
|
324 |
+
"cfg_scale": cfg_scale,
|
325 |
+
"width": width,
|
326 |
+
"height": height,
|
327 |
+
"seed": seed
|
328 |
+
})
|
329 |
+
progress(0.75, desc="Opening image")
|
330 |
+
|
331 |
+
job = prodia_client.wait(result)
|
332 |
+
progress(0.99, desc="Sending image")
|
333 |
+
time.sleep(0.5)
|
334 |
+
return [job["imageUrl"]], job["imageUrl"]
|
335 |
+
|
336 |
+
|
337 |
+
|
338 |
+
|
339 |
+
|
340 |
|
341 |
css = """
|
342 |
#generate {
|
|
|
497 |
send_to_png.click(send_to_img2img_def, inputs=past_url, outputs=image_input)
|
498 |
send_to_img2img_png.click(send_to_img2img_def, inputs=past_url, outputs=i2i_image_input)
|
499 |
send_to_png_i2i.click(send_to_img2img_def, inputs=i2i_past_url, outputs=image_input)
|
500 |
+
with gr.Tab("XL Inference"):
|
501 |
+
with gr.Row():
|
502 |
+
with gr.Column(scale=6):
|
503 |
+
xl_model = gr.Dropdown(interactive=True, show_label=True,
|
504 |
+
label="Stable Diffusion XL Checkpoint", choices=prodia_client.xl_list_models())
|
505 |
+
|
506 |
+
with gr.Tab("txt2img"):
|
507 |
+
with gr.Row():
|
508 |
+
with gr.Column(scale=6, min_width=600):
|
509 |
+
xl_prompt = gr.Textbox(placeholder="Prompt", show_label=False, lines=3, scale=3)
|
510 |
+
xl_negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=False, lines=3, scale=1,
|
511 |
+
value="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation")
|
512 |
+
with gr.Column():
|
513 |
+
xl_text_button = gr.Button("Generate", variant='primary', elem_id="generate")
|
514 |
+
|
515 |
+
with gr.Row():
|
516 |
+
with gr.Column(scale=3):
|
517 |
+
with gr.Tab("Generation"):
|
518 |
+
with gr.Row():
|
519 |
+
with gr.Column(scale=1):
|
520 |
+
xl_sampler = gr.Dropdown(value="DPM++ 2M Karras", show_label=True, label="Sampling Method",
|
521 |
+
choices=prodia_client.xl_list_samplers())
|
522 |
+
|
523 |
+
with gr.Column(scale=1):
|
524 |
+
xl_steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=25, value=20, step=1)
|
525 |
+
|
526 |
+
with gr.Row():
|
527 |
+
with gr.Column(scale=1):
|
528 |
+
xl_width = gr.Slider(label="Width", maximum=1024, value=512, step=8)
|
529 |
+
xl_height = gr.Slider(label="Height", maximum=1024, value=512, step=8)
|
530 |
+
|
531 |
+
with gr.Column(scale=1):
|
532 |
+
xl_batch_size = gr.Slider(label="Batch Size", maximum=1, value=1)
|
533 |
+
xl_batch_count = gr.Slider(label="Batch Count", maximum=1, value=1)
|
534 |
+
|
535 |
+
xl_cfg_scale = gr.Slider(label="CFG Scale", minimum=0.1, maximum=20, value=8, step=0.1)
|
536 |
+
xl_seed = gr.Number(label="Seed", value=-1)
|
537 |
+
|
538 |
+
with gr.Column(scale=2):
|
539 |
+
xl_image_output = gr.Gallery(show_label=False, rows=2, preview=True)
|
540 |
+
xl_send_to_img2img = gr.Button(value="Send OUTPUT IMAGE to img2img")
|
541 |
+
xl_send_to_png = gr.Button(value="Send OUTPUT IMAGE to PNG Info")
|
542 |
+
xl_past_url = gr.Textbox(visible=False, interactive=False)
|
543 |
+
|
544 |
+
xl_text_button.click(xl_txt2img, inputs=[xl_prompt, xl_negative_prompt, xl_model, xl_steps, xl_sampler, xl_cfg_scale, xl_width, xl_height,
|
545 |
+
xl_seed], outputs=[xl_image_output, xl_past_url], concurrency_limit=64)
|
546 |
+
|
547 |
+
with gr.Tab("img2img"):
|
548 |
+
with gr.Row():
|
549 |
+
with gr.Column(scale=6, min_width=600):
|
550 |
+
xl_i2i_prompt = gr.Textbox(placeholder="Prompt", show_label=False, lines=3, scale=3)
|
551 |
+
xl_i2i_negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=False, lines=3, scale=1,
|
552 |
+
value="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation")
|
553 |
+
with gr.Column():
|
554 |
+
xl_i2i_text_button = gr.Button("Generate", variant='primary', elem_id="generate")
|
555 |
+
|
556 |
+
with gr.Row():
|
557 |
+
with gr.Column(scale=3):
|
558 |
+
with gr.Tab("Generation"):
|
559 |
+
xl_i2i_image_input = gr.Image(type="pil", interactive=True)
|
560 |
+
|
561 |
+
with gr.Row():
|
562 |
+
with gr.Column(scale=1):
|
563 |
+
xl_i2i_sampler = gr.Dropdown(value="DPM++ 2M Karras", show_label=True, label="Sampling Method",
|
564 |
+
choices=prodia_client.xl_list_samplers())
|
565 |
+
|
566 |
+
with gr.Column(scale=1):
|
567 |
+
xl_i2i_steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=25, value=20, step=1)
|
568 |
+
with gr.Row():
|
569 |
+
with gr.Column(scale=1):
|
570 |
+
xl_i2i_width = gr.Slider(label="Width", maximum=1024, value=512, step=8)
|
571 |
+
xl_i2i_height = gr.Slider(label="Height", maximum=1024, value=512, step=8)
|
572 |
+
|
573 |
+
with gr.Column(scale=1):
|
574 |
+
xl_i2i_batch_size = gr.Slider(label="Batch Size", maximum=1, value=1)
|
575 |
+
xl_i2i_batch_count = gr.Slider(label="Batch Count", maximum=1, value=1)
|
576 |
+
|
577 |
+
xl_i2i_cfg_scale = gr.Slider(label="CFG Scale", minimum=0.1, maximum=20, value=7, step=0.1)
|
578 |
+
xl_i2i_denoising = gr.Slider(label="Denoising Strength", minimum=0, maximum=1, value=0.7, step=0.1)
|
579 |
+
xl_i2i_seed = gr.Number(label="Seed", value=-1)
|
580 |
+
|
581 |
+
|
582 |
+
with gr.Column(scale=2):
|
583 |
+
xl_i2i_image_output = gr.Gallery(show_label=False, rows=2, preview=True)
|
584 |
+
xl_send_to_png_i2i = gr.Button(value="Send INPUT IMAGE to PNG Info")
|
585 |
+
xl_i2i_past_url = gr.Textbox(visible=False, interactive=False)
|
586 |
+
|
587 |
+
xl_i2i_text_button.click(xl_img2img, inputs=[xl_i2i_image_input, xl_i2i_denoising, xl_i2i_prompt, xl_i2i_negative_prompt,
|
588 |
+
xl_model, xl_i2i_steps, xl_i2i_sampler, xl_i2i_cfg_scale, xl_i2i_width, xl_i2i_height,
|
589 |
+
xl_i2i_seed], outputs=[xl_i2i_image_output, xl_i2i_past_url], concurrency_limit=64)
|
590 |
+
xl_send_to_img2img.click(send_to_img2img_def, inputs=xl_past_url, outputs=xl_i2i_image_input)
|
591 |
+
xl_send_to_png.click(send_to_img2img_def, inputs=xl_past_url, outputs=image_input)
|
592 |
+
xl_send_to_png_i2i.click(send_to_img2img_def, inputs=xl_i2i_past_url, outputs=image_input)
|
593 |
with gr.Tab("HuggingFace Inference"):
|
594 |
with gr.Row():
|
595 |
gr.Markdown("Add your model from HF.co, enter model ID.")
|