Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,19 +43,11 @@ def update_imgbox(choices):
|
|
| 43 |
choices_plus = extend_choices(choices[:num_models])
|
| 44 |
return [gr.Image(None, label=m, visible=(m!='NA')) for m in choices_plus]
|
| 45 |
|
| 46 |
-
async def infer(model_str, prompt,
|
| 47 |
from pathlib import Path
|
| 48 |
-
kwargs = {
|
| 49 |
-
"seed": seed,
|
| 50 |
-
"negative_prompt": negative_prompt,
|
| 51 |
-
"width": width,
|
| 52 |
-
"height": height,
|
| 53 |
-
"steps": steps,
|
| 54 |
-
"cfg": cfg,
|
| 55 |
-
"strength": strength,
|
| 56 |
-
"method": method
|
| 57 |
-
}
|
| 58 |
noise = ""
|
|
|
|
| 59 |
task = asyncio.create_task(asyncio.to_thread(models_load[model_str].fn,
|
| 60 |
prompt=f'{prompt} {noise}', **kwargs, token=HF_TOKEN))
|
| 61 |
await asyncio.sleep(0)
|
|
@@ -75,12 +67,12 @@ async def infer(model_str, prompt, negative_prompt, width, height, steps, cfg, s
|
|
| 75 |
return None
|
| 76 |
|
| 77 |
|
| 78 |
-
def gen_fnseed(model_str, prompt,
|
| 79 |
if model_str == 'NA':
|
| 80 |
return None
|
| 81 |
try:
|
| 82 |
loop = asyncio.new_event_loop()
|
| 83 |
-
result = loop.run_until_complete(infer(model_str, prompt,
|
| 84 |
except (Exception, asyncio.CancelledError) as e:
|
| 85 |
print(e)
|
| 86 |
print(f"Task aborted: {model_str}")
|
|
@@ -122,7 +114,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
|
|
| 122 |
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
| 123 |
with gr.Row():
|
| 124 |
# Slider for setting the seed for reproducibility
|
| 125 |
-
|
| 126 |
with gr.Row():
|
| 127 |
# Radio buttons for selecting the sampling method
|
| 128 |
method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
|
@@ -145,7 +137,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
|
|
| 145 |
|
| 146 |
for m, o in zip(current_models, output):
|
| 147 |
gen_event = gr.on(triggers=[gen_button.click, txt_input.submit], fn=gen_fnseed,
|
| 148 |
-
inputs=[m, txt_input,
|
| 149 |
#stop_button.click(lambda s: gr.update(interactive = False), None, stop_button, cancels = [gen_event])
|
| 150 |
with gr.Accordion('Model selection'):
|
| 151 |
model_choice = gr.CheckboxGroup(models, label = f'Choose up to {int(num_models)} different models from the {len(models)} available!', value=default_models, interactive=True)
|
|
|
|
| 43 |
choices_plus = extend_choices(choices[:num_models])
|
| 44 |
return [gr.Image(None, label=m, visible=(m!='NA')) for m in choices_plus]
|
| 45 |
|
| 46 |
+
async def infer(model_str, prompt, seed=1, timeout=inference_timeout):
|
| 47 |
from pathlib import Path
|
| 48 |
+
kwargs = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
noise = ""
|
| 50 |
+
kwargs["seed"] = seed
|
| 51 |
task = asyncio.create_task(asyncio.to_thread(models_load[model_str].fn,
|
| 52 |
prompt=f'{prompt} {noise}', **kwargs, token=HF_TOKEN))
|
| 53 |
await asyncio.sleep(0)
|
|
|
|
| 67 |
return None
|
| 68 |
|
| 69 |
|
| 70 |
+
def gen_fnseed(model_str, prompt, seed=1):
|
| 71 |
if model_str == 'NA':
|
| 72 |
return None
|
| 73 |
try:
|
| 74 |
loop = asyncio.new_event_loop()
|
| 75 |
+
result = loop.run_until_complete(infer(model_str, prompt, seed, inference_timeout))
|
| 76 |
except (Exception, asyncio.CancelledError) as e:
|
| 77 |
print(e)
|
| 78 |
print(f"Task aborted: {model_str}")
|
|
|
|
| 114 |
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
| 115 |
with gr.Row():
|
| 116 |
# Slider for setting the seed for reproducibility
|
| 117 |
+
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
| 118 |
with gr.Row():
|
| 119 |
# Radio buttons for selecting the sampling method
|
| 120 |
method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
|
|
|
| 137 |
|
| 138 |
for m, o in zip(current_models, output):
|
| 139 |
gen_event = gr.on(triggers=[gen_button.click, txt_input.submit], fn=gen_fnseed,
|
| 140 |
+
inputs=[m, txt_input, seed], outputs=[o], concurrency_limit=None, queue=False)
|
| 141 |
#stop_button.click(lambda s: gr.update(interactive = False), None, stop_button, cancels = [gen_event])
|
| 142 |
with gr.Accordion('Model selection'):
|
| 143 |
model_choice = gr.CheckboxGroup(models, label = f'Choose up to {int(num_models)} different models from the {len(models)} available!', value=default_models, interactive=True)
|