Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -29,9 +29,10 @@ load_fn(models)
|
|
29 |
|
30 |
|
31 |
num_models = 6
|
32 |
-
|
33 |
default_models = models[:num_models]
|
34 |
inference_timeout = 600
|
|
|
35 |
|
36 |
def extend_choices(choices):
|
37 |
return choices[:num_models] + (num_models - len(choices[:num_models])) * ['NA']
|
@@ -47,9 +48,62 @@ def gen_fn(model_str, prompt):
|
|
47 |
noise = str('') #str(randint(0, 99999999999))
|
48 |
return models_load[model_str](f'{prompt} {noise}')
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
with gr.Tab('Toy World'):
|
54 |
txt_input = gr.Textbox(label='Your prompt:', lines=4)
|
55 |
gen_button = gr.Button('Generate up to 6 images in up to 3 minutes total')
|
@@ -87,7 +141,46 @@ with gr.Blocks() as demo:
|
|
87 |
<p> Based on the <a href="https://huggingface.co/spaces/John6666/hfd_test_nostopbutton">Huggingface NoStopButton</a> Space by John6666, <a href="https://huggingface.co/spaces/derwahnsinn/TestGen">TestGen</a> Space by derwahnsinn, the <a href="https://huggingface.co/spaces/RdnUser77/SpacIO_v1">SpacIO</a> Space by RdnUser77 and Omnibus's Maximum Multiplier! For 6 images with the same model check out the <a href="https://huggingface.co/spaces/Yntec/PrintingPress">Printing Press</a>, for the classic UI with prompt enhancer try <a href="https://huggingface.co/spaces/Yntec/blitz_diffusion">Blitz Diffusion!</a>
|
88 |
</p>
|
89 |
"""
|
90 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
demo.queue(default_concurrency_limit=200, max_size=200)
|
93 |
demo.launch(show_api=False, max_threads=400)
|
|
|
29 |
|
30 |
|
31 |
num_models = 6
|
32 |
+
MAX_SEED = 3999999999
|
33 |
default_models = models[:num_models]
|
34 |
inference_timeout = 600
|
35 |
+
starting_seed = randint(1941, 2024)
|
36 |
|
37 |
def extend_choices(choices):
|
38 |
return choices[:num_models] + (num_models - len(choices[:num_models])) * ['NA']
|
|
|
48 |
noise = str('') #str(randint(0, 99999999999))
|
49 |
return models_load[model_str](f'{prompt} {noise}')
|
50 |
|
51 |
+
async def infer(model_str, prompt, seed=1, timeout=inference_timeout):
|
52 |
+
from pathlib import Path
|
53 |
+
kwargs = {}
|
54 |
+
noise = ""
|
55 |
+
kwargs["seed"] = seed
|
56 |
+
task = asyncio.create_task(asyncio.to_thread(models_load[model_str].fn,
|
57 |
+
prompt=f'{prompt} {noise}', **kwargs, token=HF_TOKEN))
|
58 |
+
await asyncio.sleep(0)
|
59 |
+
try:
|
60 |
+
result = await asyncio.wait_for(task, timeout=timeout)
|
61 |
+
except (Exception, asyncio.TimeoutError) as e:
|
62 |
+
print(e)
|
63 |
+
print(f"Task timed out: {model_str}")
|
64 |
+
if not task.done(): task.cancel()
|
65 |
+
result = None
|
66 |
+
if task.done() and result is not None:
|
67 |
+
with lock:
|
68 |
+
png_path = "image.png"
|
69 |
+
result.save(png_path)
|
70 |
+
image = str(Path(png_path).resolve())
|
71 |
+
return image
|
72 |
+
return None
|
73 |
+
|
74 |
+
def gen_fnseed(model_str, prompt, seed=1):
|
75 |
+
if model_str == 'NA':
|
76 |
+
return None
|
77 |
+
try:
|
78 |
+
loop = asyncio.new_event_loop()
|
79 |
+
result = loop.run_until_complete(infer(model_str, prompt, seed, inference_timeout))
|
80 |
+
except (Exception, asyncio.CancelledError) as e:
|
81 |
+
print(e)
|
82 |
+
print(f"Task aborted: {model_str}")
|
83 |
+
result = None
|
84 |
+
finally:
|
85 |
+
loop.close()
|
86 |
+
return result
|
87 |
+
|
88 |
+
css="""
|
89 |
+
.wrapper img {font-size: 98% !important; white-space: nowrap !important; text-align: center !important;
|
90 |
+
display: inline-block !important;}
|
91 |
+
"""
|
92 |
+
|
93 |
+
with gr.Blocks(css=css) as demo:
|
94 |
+
|
95 |
+
gr.HTML(
|
96 |
+
"""
|
97 |
+
<div style="text-align: center; max-width: 1200px; margin: 0 auto;">
|
98 |
+
<div>
|
99 |
+
<body>
|
100 |
+
<div class="wrapper"><p style="margin-bottom: 10px;"><img src="https://huggingface.co/Yntec/DucHaitenLofi/resolve/main/NEW.webp" alt="NEW!" style="width:32px;height:16px;"> - A tab where you can use seeds has been added!</p>
|
101 |
+
</div>
|
102 |
+
</body>
|
103 |
+
</div>
|
104 |
+
</div>
|
105 |
+
"""
|
106 |
+
)
|
107 |
with gr.Tab('Toy World'):
|
108 |
txt_input = gr.Textbox(label='Your prompt:', lines=4)
|
109 |
gen_button = gr.Button('Generate up to 6 images in up to 3 minutes total')
|
|
|
141 |
<p> Based on the <a href="https://huggingface.co/spaces/John6666/hfd_test_nostopbutton">Huggingface NoStopButton</a> Space by John6666, <a href="https://huggingface.co/spaces/derwahnsinn/TestGen">TestGen</a> Space by derwahnsinn, the <a href="https://huggingface.co/spaces/RdnUser77/SpacIO_v1">SpacIO</a> Space by RdnUser77 and Omnibus's Maximum Multiplier! For 6 images with the same model check out the <a href="https://huggingface.co/spaces/Yntec/PrintingPress">Printing Press</a>, for the classic UI with prompt enhancer try <a href="https://huggingface.co/spaces/Yntec/blitz_diffusion">Blitz Diffusion!</a>
|
142 |
</p>
|
143 |
"""
|
144 |
+
)
|
145 |
+
with gr.Tab('🌱 Use seeds!'):
|
146 |
+
txt_inputseed = gr.Textbox(label='Your prompt:', lines=4)
|
147 |
+
gen_buttonseed = gr.Button('Generate up to 6 images with the same seed in up to 3 minutes total')
|
148 |
+
seed = gr.Slider(label="Use a seed to replicate the same image later (maximum 3999999999)", minimum=0, maximum=MAX_SEED, step=1, value=starting_seed, scale=3)
|
149 |
+
#stop_button = gr.Button('Stop', variant = 'secondary', interactive = False)
|
150 |
+
gen_buttonseed.click(lambda s: gr.update(interactive = True), None)
|
151 |
+
gr.HTML(
|
152 |
+
"""
|
153 |
+
<div style="text-align: center; max-width: 1200px; margin: 0 auto;">
|
154 |
+
<div>
|
155 |
+
<body>
|
156 |
+
<div class="center"><p style="margin-bottom: 10px; color: #000000;">Scroll down to see more images and select models.</p>
|
157 |
+
</div>
|
158 |
+
</body>
|
159 |
+
</div>
|
160 |
+
</div>
|
161 |
+
"""
|
162 |
+
)
|
163 |
+
with gr.Row():
|
164 |
+
output = [gr.Image(label = m, min_width=480) for m in default_models]
|
165 |
+
current_models = [gr.Textbox(m, visible = False) for m in default_models]
|
166 |
+
|
167 |
+
for m, o in zip(current_models, output):
|
168 |
+
gen_eventseed = gr.on(triggers=[gen_buttonseed.click, txt_inputseed.submit], fn=gen_fnseed,
|
169 |
+
inputs=[m, txt_inputseed, seed], outputs=[o], concurrency_limit=None, queue=False)
|
170 |
+
#stop_button.click(lambda s: gr.update(interactive = False), None, stop_button, cancels = [gen_event])
|
171 |
+
with gr.Accordion('Model selection'):
|
172 |
+
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)
|
173 |
+
#model_choice = gr.CheckboxGroup(models, label = f'Choose up to {num_models} different models from the 2 available! Untick them to only use one!', value = default_models, multiselect = True, max_choices = num_models, interactive = True, filterable = False)
|
174 |
+
model_choice.change(update_imgbox, model_choice, output)
|
175 |
+
model_choice.change(extend_choices, model_choice, current_models)
|
176 |
+
with gr.Row():
|
177 |
+
gr.HTML(
|
178 |
+
"""
|
179 |
+
<div class="footer">
|
180 |
+
<p> Based on the <a href="https://huggingface.co/spaces/John6666/hfd_test_nostopbutton">Huggingface NoStopButton</a> Space by John6666, <a href="https://huggingface.co/spaces/derwahnsinn/TestGen">TestGen</a> Space by derwahnsinn, the <a href="https://huggingface.co/spaces/RdnUser77/SpacIO_v1">SpacIO</a> Space by RdnUser77 and Omnibus's Maximum Multiplier! For 6 images with the same model check out the <a href="https://huggingface.co/spaces/Yntec/PrintingPress">Printing Press</a>, for the classic UI with prompt enhancer try <a href="https://huggingface.co/spaces/Yntec/blitz_diffusion">Blitz Diffusion!</a>
|
181 |
+
</p>
|
182 |
+
"""
|
183 |
+
)
|
184 |
|
185 |
demo.queue(default_concurrency_limit=200, max_size=200)
|
186 |
demo.launch(show_api=False, max_threads=400)
|