Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,6 @@ def get_current_time():
|
|
| 16 |
now = datetime.now()
|
| 17 |
now2 = now
|
| 18 |
current_time = now2.strftime("%y-%m-%d %H:%M:%S")
|
| 19 |
-
# ki = f'{kii} {current_time}'
|
| 20 |
return current_time
|
| 21 |
|
| 22 |
def load_fn(models):
|
|
@@ -37,10 +36,9 @@ load_fn(models)
|
|
| 37 |
|
| 38 |
num_models = 6
|
| 39 |
max_images = 6
|
| 40 |
-
inference_timeout =
|
| 41 |
default_models = models[:num_models]
|
| 42 |
MAX_SEED = 2**32-1
|
| 43 |
-
loopcounter = 1
|
| 44 |
|
| 45 |
|
| 46 |
def extend_choices(choices):
|
|
@@ -66,10 +64,15 @@ async def infer(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0
|
|
| 66 |
if width > 0: kwargs["width"] = width
|
| 67 |
if steps > 0: kwargs["num_inference_steps"] = steps
|
| 68 |
if cfg > 0: cfg = kwargs["guidance_scale"] = cfg
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
await asyncio.sleep(0)
|
| 74 |
try:
|
| 75 |
result = await asyncio.wait_for(task, timeout=timeout)
|
|
@@ -87,9 +90,9 @@ async def infer(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0
|
|
| 87 |
if task.done() and result is not None and not isinstance(result, tuple):
|
| 88 |
with lock:
|
| 89 |
# png_path = "img.png"
|
| 90 |
-
|
| 91 |
-
png_path =
|
| 92 |
-
|
| 93 |
image = save_image(result, png_path, model_str, prompt, nprompt, height, width, steps, cfg, seed)
|
| 94 |
return image
|
| 95 |
return None
|
|
@@ -127,7 +130,6 @@ CSS="""
|
|
| 127 |
js_func = """
|
| 128 |
function refresh() {
|
| 129 |
const url = new URL(window.location);
|
| 130 |
-
|
| 131 |
if (url.searchParams.get('__theme') !== 'dark') {
|
| 132 |
url.searchParams.set('__theme', 'dark');
|
| 133 |
window.location.href = url.href;
|
|
@@ -135,13 +137,29 @@ function refresh() {
|
|
| 135 |
}
|
| 136 |
"""
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=CSS) as demo:
|
| 139 |
# with gr.Blocks(theme='JohnSmith9982/small_and_pretty', fill_width=True, css=CSS, js=js_func) as demo:
|
| 140 |
gr.HTML("")
|
| 141 |
with gr.Tab('6 Models'):
|
| 142 |
with gr.Column(scale=2):
|
| 143 |
with gr.Group():
|
| 144 |
-
txt_input = gr.Textbox(label='Your prompt:', value=preSetPrompt, lines=
|
| 145 |
neg_input = gr.Textbox(label='Negative prompt:', value=negPreSetPrompt, lines=1)
|
| 146 |
with gr.Accordion("Advanced", open=False, visible=True):
|
| 147 |
with gr.Row():
|
|
@@ -193,7 +211,7 @@ with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=CSS) as demo:
|
|
| 193 |
with gr.Group():
|
| 194 |
# global preSetPrompt
|
| 195 |
# global negPreSetPrompt
|
| 196 |
-
txt_input2 = gr.Textbox(label='Your prompt:', value = preSetPrompt, lines=
|
| 197 |
neg_input2 = gr.Textbox(label='Negative prompt:', value=negPreSetPrompt, lines=1)
|
| 198 |
with gr.Accordion("Advanced", open=False, visible=True):
|
| 199 |
with gr.Row():
|
|
@@ -203,11 +221,11 @@ with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=CSS) as demo:
|
|
| 203 |
steps2 = gr.Slider(label="Number of inference steps", info="If 0, the default value is used.", maximum=100, step=1, value=0)
|
| 204 |
cfg2 = gr.Slider(label="Guidance scale", info="If 0, the default value is used.", maximum=30.0, step=0.1, value=0)
|
| 205 |
seed2 = gr.Slider(label="Seed", info="Randomize Seed if -1.", minimum=-1, maximum=MAX_SEED, step=1, value=-1)
|
| 206 |
-
seed_rand2 = gr.Button("Randomize Seed
|
| 207 |
seed_rand2.click(randomize_seed, None, [seed2], queue=False)
|
| 208 |
num_images = gr.Slider(1, max_images, value=max_images, step=1, label='Number of images')
|
| 209 |
with gr.Row():
|
| 210 |
-
gen_button2 = gr.Button('
|
| 211 |
#stop_button2 = gr.Button('Stop', variant='stop', interactive=False, scale=1)
|
| 212 |
#gen_button2.click(lambda: gr.update(interactive=True), None, stop_button2)
|
| 213 |
|
|
@@ -233,8 +251,10 @@ with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=CSS) as demo:
|
|
| 233 |
concurrency_limit=None, queue=False) # Be sure to delete ", queue=False" when activating the stop button
|
| 234 |
o.change(add_gallery, [o, model_choice2, gallery2], [gallery2])
|
| 235 |
#stop_button2.click(lambda: gr.update(interactive=False), None, stop_button2, cancels=[gen_event2])
|
| 236 |
-
|
|
|
|
| 237 |
gr.Markdown("")
|
| 238 |
|
| 239 |
-
#demo.queue(default_concurrency_limit=200, max_size=200)
|
| 240 |
demo.launch(show_api=False, max_threads=400)
|
|
|
|
|
|
| 16 |
now = datetime.now()
|
| 17 |
now2 = now
|
| 18 |
current_time = now2.strftime("%y-%m-%d %H:%M:%S")
|
|
|
|
| 19 |
return current_time
|
| 20 |
|
| 21 |
def load_fn(models):
|
|
|
|
| 36 |
|
| 37 |
num_models = 6
|
| 38 |
max_images = 6
|
| 39 |
+
inference_timeout = 400
|
| 40 |
default_models = models[:num_models]
|
| 41 |
MAX_SEED = 2**32-1
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
def extend_choices(choices):
|
|
|
|
| 64 |
if width > 0: kwargs["width"] = width
|
| 65 |
if steps > 0: kwargs["num_inference_steps"] = steps
|
| 66 |
if cfg > 0: cfg = kwargs["guidance_scale"] = cfg
|
| 67 |
+
|
| 68 |
+
if seed == -1:
|
| 69 |
+
theSeed = randomize_seed()
|
| 70 |
+
kwargs["seed"] = theSeed
|
| 71 |
+
else:
|
| 72 |
+
kwargs["seed"] = seed
|
| 73 |
+
theSeed = seed
|
| 74 |
+
|
| 75 |
+
task = asyncio.create_task(asyncio.to_thread(models_load[model_str].fn, prompt=prompt, negative_prompt=nprompt, **kwargs, token=HF_TOKEN))
|
| 76 |
await asyncio.sleep(0)
|
| 77 |
try:
|
| 78 |
result = await asyncio.wait_for(task, timeout=timeout)
|
|
|
|
| 90 |
if task.done() and result is not None and not isinstance(result, tuple):
|
| 91 |
with lock:
|
| 92 |
# png_path = "img.png"
|
| 93 |
+
# png_path = get_current_time() + "_" + model_str.replace("/", "_") + ".png"
|
| 94 |
+
# png_path = model_str.replace("/", "_") + " - " + prompt + " - " + get_current_time() + ".png"
|
| 95 |
+
png_path = model_str.replace("/", "_") + " - " + get_current_time() + "_" + str(theSeed) + ".png"
|
| 96 |
image = save_image(result, png_path, model_str, prompt, nprompt, height, width, steps, cfg, seed)
|
| 97 |
return image
|
| 98 |
return None
|
|
|
|
| 130 |
js_func = """
|
| 131 |
function refresh() {
|
| 132 |
const url = new URL(window.location);
|
|
|
|
| 133 |
if (url.searchParams.get('__theme') !== 'dark') {
|
| 134 |
url.searchParams.set('__theme', 'dark');
|
| 135 |
window.location.href = url.href;
|
|
|
|
| 137 |
}
|
| 138 |
"""
|
| 139 |
|
| 140 |
+
js_AutoSave="""
|
| 141 |
+
console.log("Yo");
|
| 142 |
+
|
| 143 |
+
var img1 = document.querySelector("div#component-355 .svelte-1kpcxni button.svelte-1kpcxni .svelte-1kpcxni img"),
|
| 144 |
+
observer = new MutationObserver((changes) => {
|
| 145 |
+
changes.forEach(change => {
|
| 146 |
+
if(change.attributeName.includes('src')){
|
| 147 |
+
console.log(img1.src);
|
| 148 |
+
document.querySelector("div#component-355 .svelte-1kpcxni .svelte-sr71km a.svelte-1s8vnbx button").click();
|
| 149 |
+
}
|
| 150 |
+
});
|
| 151 |
+
});
|
| 152 |
+
observer.observe(img1, {attributes : true});
|
| 153 |
+
|
| 154 |
+
"""
|
| 155 |
+
|
| 156 |
with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=CSS) as demo:
|
| 157 |
# with gr.Blocks(theme='JohnSmith9982/small_and_pretty', fill_width=True, css=CSS, js=js_func) as demo:
|
| 158 |
gr.HTML("")
|
| 159 |
with gr.Tab('6 Models'):
|
| 160 |
with gr.Column(scale=2):
|
| 161 |
with gr.Group():
|
| 162 |
+
txt_input = gr.Textbox(label='Your prompt:', value=preSetPrompt, lines=3, autofocus=1)
|
| 163 |
neg_input = gr.Textbox(label='Negative prompt:', value=negPreSetPrompt, lines=1)
|
| 164 |
with gr.Accordion("Advanced", open=False, visible=True):
|
| 165 |
with gr.Row():
|
|
|
|
| 211 |
with gr.Group():
|
| 212 |
# global preSetPrompt
|
| 213 |
# global negPreSetPrompt
|
| 214 |
+
txt_input2 = gr.Textbox(label='Your prompt:', value = preSetPrompt, lines=3, autofocus=1)
|
| 215 |
neg_input2 = gr.Textbox(label='Negative prompt:', value=negPreSetPrompt, lines=1)
|
| 216 |
with gr.Accordion("Advanced", open=False, visible=True):
|
| 217 |
with gr.Row():
|
|
|
|
| 221 |
steps2 = gr.Slider(label="Number of inference steps", info="If 0, the default value is used.", maximum=100, step=1, value=0)
|
| 222 |
cfg2 = gr.Slider(label="Guidance scale", info="If 0, the default value is used.", maximum=30.0, step=0.1, value=0)
|
| 223 |
seed2 = gr.Slider(label="Seed", info="Randomize Seed if -1.", minimum=-1, maximum=MAX_SEED, step=1, value=-1)
|
| 224 |
+
seed_rand2 = gr.Button("Randomize Seed", size="sm", variant="secondary")
|
| 225 |
seed_rand2.click(randomize_seed, None, [seed2], queue=False)
|
| 226 |
num_images = gr.Slider(1, max_images, value=max_images, step=1, label='Number of images')
|
| 227 |
with gr.Row():
|
| 228 |
+
gen_button2 = gr.Button('Let the machine halucinate', variant='primary', scale=2)
|
| 229 |
#stop_button2 = gr.Button('Stop', variant='stop', interactive=False, scale=1)
|
| 230 |
#gen_button2.click(lambda: gr.update(interactive=True), None, stop_button2)
|
| 231 |
|
|
|
|
| 251 |
concurrency_limit=None, queue=False) # Be sure to delete ", queue=False" when activating the stop button
|
| 252 |
o.change(add_gallery, [o, model_choice2, gallery2], [gallery2])
|
| 253 |
#stop_button2.click(lambda: gr.update(interactive=False), None, stop_button2, cancels=[gen_event2])
|
| 254 |
+
|
| 255 |
+
# gr.Markdown(js_AutoSave)
|
| 256 |
gr.Markdown("")
|
| 257 |
|
| 258 |
+
# demo.queue(default_concurrency_limit=200, max_size=200)
|
| 259 |
demo.launch(show_api=False, max_threads=400)
|
| 260 |
+
# demo.launch(show_api=False, max_threads=400, js=js_AutoSave)
|