Spaces:
Paused
Paused
Commit
·
b33f45e
1
Parent(s):
2c94a8a
migration to gradio 4.4.0 (#39)
Browse files- migration to gradio 4.4.0 (8f0563f60618693ab351249eaf11b5f52cfd7858)
Co-authored-by: Zenafey Baenro <zenafey@users.noreply.huggingface.co>
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import numpy as np
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import time
|
|
@@ -6,12 +5,11 @@ import json
|
|
| 6 |
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:
|
| 16 |
def __init__(self, api_key, base=None):
|
| 17 |
self.base = base or "https://api.prodia.com/v1"
|
|
@@ -83,6 +81,7 @@ def image_to_base64(image):
|
|
| 83 |
|
| 84 |
return img_str.decode('utf-8') # Convert bytes to string
|
| 85 |
|
|
|
|
| 86 |
def remove_id_and_ext(text):
|
| 87 |
text = re.sub(r'\[.*\]$', '', text)
|
| 88 |
extension = text[-12:].strip()
|
|
@@ -92,6 +91,7 @@ def remove_id_and_ext(text):
|
|
| 92 |
text = text[:-4]
|
| 93 |
return text
|
| 94 |
|
|
|
|
| 95 |
def get_data(text):
|
| 96 |
results = {}
|
| 97 |
patterns = {
|
|
@@ -119,9 +119,10 @@ def get_data(text):
|
|
| 119 |
results['h'] = None
|
| 120 |
return results
|
| 121 |
|
|
|
|
| 122 |
def send_to_txt2img(image):
|
| 123 |
-
|
| 124 |
-
result = {tabs: gr.
|
| 125 |
|
| 126 |
try:
|
| 127 |
text = image.info['parameters']
|
|
@@ -142,15 +143,6 @@ def send_to_txt2img(image):
|
|
| 142 |
|
| 143 |
except Exception as e:
|
| 144 |
print(e)
|
| 145 |
-
result[prompt] = gr.update()
|
| 146 |
-
result[negative_prompt] = gr.update()
|
| 147 |
-
result[steps] = gr.update()
|
| 148 |
-
result[seed] = gr.update()
|
| 149 |
-
result[cfg_scale] = gr.update()
|
| 150 |
-
result[width] = gr.update()
|
| 151 |
-
result[height] = gr.update()
|
| 152 |
-
result[sampler] = gr.update()
|
| 153 |
-
result[model] = gr.update()
|
| 154 |
|
| 155 |
return result
|
| 156 |
|
|
@@ -163,6 +155,7 @@ for model_name in model_list:
|
|
| 163 |
name_without_ext = remove_id_and_ext(model_name)
|
| 164 |
model_names[name_without_ext] = model_name
|
| 165 |
|
|
|
|
| 166 |
def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed):
|
| 167 |
result = prodia_client.generate({
|
| 168 |
"prompt": prompt,
|
|
@@ -180,6 +173,7 @@ def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, he
|
|
| 180 |
|
| 181 |
return job["imageUrl"]
|
| 182 |
|
|
|
|
| 183 |
def img2img(input_image, denoising, prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed):
|
| 184 |
result = prodia_client.transform({
|
| 185 |
"imageData": image_to_base64(input_image),
|
|
@@ -214,7 +208,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 214 |
with gr.Column(scale=1):
|
| 215 |
gr.Markdown(elem_id="powered-by-prodia", value="AUTOMATIC1111 Stable Diffusion Web UI.<br>Powered by [Prodia](https://prodia.com).<br>For more features and faster generation times check out our [API Docs](https://docs.prodia.com/reference/getting-started-guide).")
|
| 216 |
|
| 217 |
-
|
| 218 |
with gr.Tabs() as tabs:
|
| 219 |
with gr.Tab("txt2img", id='t2i'):
|
| 220 |
with gr.Row():
|
|
@@ -245,12 +238,12 @@ with gr.Blocks(css=css) as demo:
|
|
| 245 |
|
| 246 |
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
|
| 247 |
seed = gr.Number(label="Seed", value=-1)
|
| 248 |
-
|
| 249 |
-
|
| 250 |
with gr.Column(scale=2):
|
| 251 |
image_output = gr.Image(value="https://images.prodia.xyz/8ede1a7c-c0ee-4ded-987d-6ffed35fc477.png")
|
| 252 |
|
| 253 |
-
text_button.click(txt2img, inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height,
|
|
|
|
| 254 |
|
| 255 |
with gr.Tab("img2img", id='i2i'):
|
| 256 |
with gr.Row():
|
|
@@ -271,7 +264,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 271 |
|
| 272 |
with gr.Column(scale=1):
|
| 273 |
i2i_steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=30, value=25, step=1)
|
| 274 |
-
|
| 275 |
with gr.Row():
|
| 276 |
with gr.Column(scale=1):
|
| 277 |
i2i_width = gr.Slider(label="Width", maximum=1024, value=512, step=8)
|
|
@@ -284,12 +277,13 @@ with gr.Blocks(css=css) as demo:
|
|
| 284 |
i2i_cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
|
| 285 |
i2i_denoising = gr.Slider(label="Denoising Strength", minimum=0, maximum=1, value=0.7, step=0.1)
|
| 286 |
i2i_seed = gr.Number(label="Seed", value=-1)
|
| 287 |
-
|
| 288 |
-
|
| 289 |
with gr.Column(scale=2):
|
| 290 |
i2i_image_output = gr.Image(value="https://images.prodia.xyz/8ede1a7c-c0ee-4ded-987d-6ffed35fc477.png")
|
| 291 |
|
| 292 |
-
i2i_text_button.click(img2img, inputs=[i2i_image_input, i2i_denoising, i2i_prompt, i2i_negative_prompt,
|
|
|
|
|
|
|
| 293 |
|
| 294 |
with gr.Tab("PNG Info"):
|
| 295 |
def plaintext_to_html(text, classname=None):
|
|
@@ -325,7 +319,9 @@ with gr.Blocks(css=css) as demo:
|
|
| 325 |
send_to_txt2img_btn = gr.Button("Send to txt2img")
|
| 326 |
|
| 327 |
image_input.upload(get_exif_data, inputs=[image_input], outputs=exif_output)
|
| 328 |
-
send_to_txt2img_btn.click(send_to_txt2img, inputs=[image_input], outputs=[tabs, prompt, negative_prompt,
|
| 329 |
-
|
|
|
|
|
|
|
| 330 |
|
| 331 |
-
demo.queue(
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import time
|
|
|
|
| 5 |
import base64
|
| 6 |
import os
|
| 7 |
from io import BytesIO
|
|
|
|
|
|
|
| 8 |
import html
|
| 9 |
import re
|
| 10 |
|
| 11 |
|
| 12 |
+
|
| 13 |
class Prodia:
|
| 14 |
def __init__(self, api_key, base=None):
|
| 15 |
self.base = base or "https://api.prodia.com/v1"
|
|
|
|
| 81 |
|
| 82 |
return img_str.decode('utf-8') # Convert bytes to string
|
| 83 |
|
| 84 |
+
|
| 85 |
def remove_id_and_ext(text):
|
| 86 |
text = re.sub(r'\[.*\]$', '', text)
|
| 87 |
extension = text[-12:].strip()
|
|
|
|
| 91 |
text = text[:-4]
|
| 92 |
return text
|
| 93 |
|
| 94 |
+
|
| 95 |
def get_data(text):
|
| 96 |
results = {}
|
| 97 |
patterns = {
|
|
|
|
| 119 |
results['h'] = None
|
| 120 |
return results
|
| 121 |
|
| 122 |
+
|
| 123 |
def send_to_txt2img(image):
|
| 124 |
+
|
| 125 |
+
result = {tabs: gr.update(selected="t2i")}
|
| 126 |
|
| 127 |
try:
|
| 128 |
text = image.info['parameters']
|
|
|
|
| 143 |
|
| 144 |
except Exception as e:
|
| 145 |
print(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
return result
|
| 148 |
|
|
|
|
| 155 |
name_without_ext = remove_id_and_ext(model_name)
|
| 156 |
model_names[name_without_ext] = model_name
|
| 157 |
|
| 158 |
+
|
| 159 |
def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed):
|
| 160 |
result = prodia_client.generate({
|
| 161 |
"prompt": prompt,
|
|
|
|
| 173 |
|
| 174 |
return job["imageUrl"]
|
| 175 |
|
| 176 |
+
|
| 177 |
def img2img(input_image, denoising, prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed):
|
| 178 |
result = prodia_client.transform({
|
| 179 |
"imageData": image_to_base64(input_image),
|
|
|
|
| 208 |
with gr.Column(scale=1):
|
| 209 |
gr.Markdown(elem_id="powered-by-prodia", value="AUTOMATIC1111 Stable Diffusion Web UI.<br>Powered by [Prodia](https://prodia.com).<br>For more features and faster generation times check out our [API Docs](https://docs.prodia.com/reference/getting-started-guide).")
|
| 210 |
|
|
|
|
| 211 |
with gr.Tabs() as tabs:
|
| 212 |
with gr.Tab("txt2img", id='t2i'):
|
| 213 |
with gr.Row():
|
|
|
|
| 238 |
|
| 239 |
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
|
| 240 |
seed = gr.Number(label="Seed", value=-1)
|
| 241 |
+
|
|
|
|
| 242 |
with gr.Column(scale=2):
|
| 243 |
image_output = gr.Image(value="https://images.prodia.xyz/8ede1a7c-c0ee-4ded-987d-6ffed35fc477.png")
|
| 244 |
|
| 245 |
+
text_button.click(txt2img, inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height,
|
| 246 |
+
seed], outputs=image_output, concurrency_limit=64)
|
| 247 |
|
| 248 |
with gr.Tab("img2img", id='i2i'):
|
| 249 |
with gr.Row():
|
|
|
|
| 264 |
|
| 265 |
with gr.Column(scale=1):
|
| 266 |
i2i_steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=30, value=25, step=1)
|
| 267 |
+
|
| 268 |
with gr.Row():
|
| 269 |
with gr.Column(scale=1):
|
| 270 |
i2i_width = gr.Slider(label="Width", maximum=1024, value=512, step=8)
|
|
|
|
| 277 |
i2i_cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
|
| 278 |
i2i_denoising = gr.Slider(label="Denoising Strength", minimum=0, maximum=1, value=0.7, step=0.1)
|
| 279 |
i2i_seed = gr.Number(label="Seed", value=-1)
|
| 280 |
+
|
|
|
|
| 281 |
with gr.Column(scale=2):
|
| 282 |
i2i_image_output = gr.Image(value="https://images.prodia.xyz/8ede1a7c-c0ee-4ded-987d-6ffed35fc477.png")
|
| 283 |
|
| 284 |
+
i2i_text_button.click(img2img, inputs=[i2i_image_input, i2i_denoising, i2i_prompt, i2i_negative_prompt,
|
| 285 |
+
model, i2i_steps, i2i_sampler, i2i_cfg_scale, i2i_width, i2i_height,
|
| 286 |
+
i2i_seed], outputs=i2i_image_output, concurrency_limit=64)
|
| 287 |
|
| 288 |
with gr.Tab("PNG Info"):
|
| 289 |
def plaintext_to_html(text, classname=None):
|
|
|
|
| 319 |
send_to_txt2img_btn = gr.Button("Send to txt2img")
|
| 320 |
|
| 321 |
image_input.upload(get_exif_data, inputs=[image_input], outputs=exif_output)
|
| 322 |
+
send_to_txt2img_btn.click(send_to_txt2img, inputs=[image_input], outputs=[tabs, prompt, negative_prompt,
|
| 323 |
+
steps, seed, model, sampler,
|
| 324 |
+
width, height, cfg_scale],
|
| 325 |
+
concurrency_limit=64)
|
| 326 |
|
| 327 |
+
demo.queue(max_size=80, api_open=False).launch(max_threads=256, show_api=False)
|