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