Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -133,4 +133,238 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
|
|
133 |
|
134 |
#demo.queue(default_concurrency_limit=240, max_size=240)
|
135 |
demo.launch(max_threads=400, ssr_mode=True)
|
136 |
-
# https://github.com/gradio-app/gradio/issues/6339
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
#demo.queue(default_concurrency_limit=240, max_size=240)
|
135 |
demo.launch(max_threads=400, ssr_mode=True)
|
136 |
+
# https://github.com/gradio-app/gradio/issues/6339
|
137 |
+
import gradio as gr
|
138 |
+
from random import randint
|
139 |
+
from all_models import models
|
140 |
+
|
141 |
+
def load_fn(models):
|
142 |
+
global models_load
|
143 |
+
models_load = {}
|
144 |
+
for model in models:
|
145 |
+
if model not in models_load.keys():
|
146 |
+
try:
|
147 |
+
m = gr.load(f'models/{model}')
|
148 |
+
except Exception as error:
|
149 |
+
m = gr.Interface(lambda txt: None, ['text'], ['image'])
|
150 |
+
models_load.update({model: m})
|
151 |
+
|
152 |
+
load_fn(models)
|
153 |
+
|
154 |
+
num_models = len(models)
|
155 |
+
default_models = models[:num_models]
|
156 |
+
|
157 |
+
def extend_choices(choices):
|
158 |
+
return choices + (num_models - len(choices)) * ['NA']
|
159 |
+
|
160 |
+
def update_imgbox(choices):
|
161 |
+
choices_plus = extend_choices(choices)
|
162 |
+
return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
|
163 |
+
|
164 |
+
def gen_fn(model_str, prompt):
|
165 |
+
if model_str == 'NA':
|
166 |
+
return None
|
167 |
+
noise = str(randint(0, 9999999))
|
168 |
+
return models_load[model_str](f'{prompt} {noise}')
|
169 |
+
|
170 |
+
def make_me():
|
171 |
+
with gr.Row():
|
172 |
+
with gr.Column(scale=1):
|
173 |
+
txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
|
174 |
+
with gr.Row():
|
175 |
+
gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
|
176 |
+
stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
|
177 |
+
|
178 |
+
def on_generate_click():
|
179 |
+
return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=True, elem_id="custom_stop_button")
|
180 |
+
|
181 |
+
def on_stop_click():
|
182 |
+
return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
|
183 |
+
|
184 |
+
gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
|
185 |
+
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
|
186 |
+
|
187 |
+
with gr.Row():
|
188 |
+
output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
|
189 |
+
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
190 |
+
for m, o in zip(current_models, output):
|
191 |
+
gen_event = gen_button.click(gen_fn, [m, txt_input], o)
|
192 |
+
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
|
193 |
+
|
194 |
+
with gr.Accordion('Model selection', elem_id="custom_accordion"):
|
195 |
+
model_choice = gr.CheckboxGroup(models, label=f'{num_models} different models selected', value=default_models, interactive=True, elem_id="custom_checkbox_group")
|
196 |
+
model_choice.change(update_imgbox, model_choice, output)
|
197 |
+
model_choice.change(extend_choices, model_choice, current_models)
|
198 |
+
|
199 |
+
with gr.Row():
|
200 |
+
gr.HTML("")
|
201 |
+
|
202 |
+
custom_css = """
|
203 |
+
:root {
|
204 |
+
--body-background-fill: #2d3d4f;
|
205 |
+
}
|
206 |
+
|
207 |
+
body {
|
208 |
+
background-color: var(--body-background-fill) !important;
|
209 |
+
color: #2d3d4f;
|
210 |
+
margin: 0;
|
211 |
+
padding: 0;
|
212 |
+
font-family: Arial, sans-serif;
|
213 |
+
height: 100vh;
|
214 |
+
overflow-y: auto;
|
215 |
+
}
|
216 |
+
|
217 |
+
.gradio-container {
|
218 |
+
background-color: #2d3d4f;
|
219 |
+
color: #c5c6c7;
|
220 |
+
padding: 20px;
|
221 |
+
border-radius: 8px;
|
222 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
223 |
+
width: 100%;
|
224 |
+
max-width: 1200px;
|
225 |
+
margin: 20px auto;
|
226 |
+
display: block;
|
227 |
+
min-height: 100vh;
|
228 |
+
}
|
229 |
+
|
230 |
+
.app_title {
|
231 |
+
background-color: #2d3d4f;
|
232 |
+
color: #c5c6c7;
|
233 |
+
padding: 10px 20px;
|
234 |
+
border-bottom: 1px solid #3b4252;
|
235 |
+
text-align: center;
|
236 |
+
font-size: 24px;
|
237 |
+
font-weight: bold;
|
238 |
+
width: 100%;
|
239 |
+
box-sizing: border-box;
|
240 |
+
margin-bottom: 20px;
|
241 |
+
}
|
242 |
+
|
243 |
+
.custom_textbox {
|
244 |
+
background-color: #2d343f;
|
245 |
+
border: 1px solid #3b4252;
|
246 |
+
color: #7f8184;
|
247 |
+
padding: 10px;
|
248 |
+
border-radius: 4px;
|
249 |
+
margin-bottom: 10px;
|
250 |
+
width: 100%;
|
251 |
+
box-sizing: border-box;
|
252 |
+
}
|
253 |
+
|
254 |
+
.custom_gen_button {
|
255 |
+
background-color: #8b38ff;
|
256 |
+
border: 1px solid #ffffff;
|
257 |
+
color: blue;
|
258 |
+
padding: 15px 32px;
|
259 |
+
text-align: center;
|
260 |
+
text-decoration: none;
|
261 |
+
display: inline-block;
|
262 |
+
font-size: 16px;
|
263 |
+
margin: 4px 2px;
|
264 |
+
cursor: pointer;
|
265 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
266 |
+
transition: transform 0.2s, box-shadow 0.2s;
|
267 |
+
border-radius: 4px;
|
268 |
+
}
|
269 |
+
.custom_gen_button:hover {
|
270 |
+
transform: translateY(-2px);
|
271 |
+
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
|
272 |
+
}
|
273 |
+
.custom_stop_button {
|
274 |
+
background-color: #6200ea;
|
275 |
+
border: 1px solid #ffffff;
|
276 |
+
color: blue;
|
277 |
+
padding: 15px 32px;
|
278 |
+
text-align: center;
|
279 |
+
text-decoration: none;
|
280 |
+
display: inline-block;
|
281 |
+
font-size: 16px;
|
282 |
+
margin: 4px 2px;
|
283 |
+
cursor: pointer;
|
284 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
285 |
+
transition: transform 0.2s, box-shadow 0.2s;
|
286 |
+
border-radius: 4px;
|
287 |
+
}
|
288 |
+
.custom_stop_button:hover {
|
289 |
+
transform: translateY(-2px);
|
290 |
+
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
|
291 |
+
}
|
292 |
+
|
293 |
+
.custom_image {
|
294 |
+
border: 1px solid #3b4252;
|
295 |
+
background-color: #2d343f;
|
296 |
+
border-radius: 4px;
|
297 |
+
margin: 10px;
|
298 |
+
max-width: 100%;
|
299 |
+
box-sizing: border-box;
|
300 |
+
}
|
301 |
+
|
302 |
+
.custom_accordion {
|
303 |
+
background-color: #2d3d4f;
|
304 |
+
color: #7f8184;
|
305 |
+
border: 1px solid #3b4252;
|
306 |
+
border-radius: 4px;
|
307 |
+
margin-top: 20px;
|
308 |
+
width: 100%;
|
309 |
+
box-sizing: border-box;
|
310 |
+
transition: margin 0.2s ease;
|
311 |
+
}
|
312 |
+
|
313 |
+
.custom_accordion .gr-accordion-header {
|
314 |
+
background-color: #2d3d4f;
|
315 |
+
color: #7f8184;
|
316 |
+
padding: 10px 20px;
|
317 |
+
border-bottom: 1px solid #5b6270;
|
318 |
+
cursor: pointer;
|
319 |
+
font-size: 18px;
|
320 |
+
font-weight: bold;
|
321 |
+
height: 40px;
|
322 |
+
display: flex;
|
323 |
+
align-items: center;
|
324 |
+
}
|
325 |
+
|
326 |
+
.custom_accordion .gr-accordion-header:hover {
|
327 |
+
background-color: #2d3d4f;
|
328 |
+
}
|
329 |
+
|
330 |
+
.custom_accordion .gr-accordion-content {
|
331 |
+
padding: 10px 20px;
|
332 |
+
background-color: #2d3d4f;
|
333 |
+
border-top: 1px solid #5b6270;
|
334 |
+
max-height: 0;
|
335 |
+
overflow: hidden;
|
336 |
+
transition: max-height 0.2s ease;
|
337 |
+
}
|
338 |
+
|
339 |
+
.custom_accordion .gr-accordion-content.open {
|
340 |
+
max-height: 500px;
|
341 |
+
}
|
342 |
+
|
343 |
+
.custom_checkbox_group {
|
344 |
+
background-color: #2d343f;
|
345 |
+
border: 1px solid #3b4252;
|
346 |
+
color: #7f8184;
|
347 |
+
border-radius: 4px;
|
348 |
+
padding: 10px;
|
349 |
+
width: 100%;
|
350 |
+
box-sizing: border-box;
|
351 |
+
}
|
352 |
+
|
353 |
+
@media (max-width: 768px) {
|
354 |
+
.gradio-container {
|
355 |
+
width: 100%;
|
356 |
+
margin: 0;
|
357 |
+
padding: 10px;
|
358 |
+
}
|
359 |
+
.custom_textbox,.custom_image,.custom_checkbox_group {
|
360 |
+
width: 100%;
|
361 |
+
box-sizing: border-box;
|
362 |
+
}
|
363 |
+
}
|
364 |
+
"""
|
365 |
+
|
366 |
+
with gr.Blocks(css=custom_css) as demo:
|
367 |
+
make_me()
|
368 |
+
|
369 |
+
demo.queue(concurrency_count=50)
|
370 |
+
demo.launch()
|