Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import gradio as gr
|
3 |
from random import randint
|
4 |
from operator import itemgetter
|
|
|
5 |
from all_models import tags_plus_models,models,models_plus_tags
|
6 |
from datetime import datetime
|
7 |
from externalmod import gr_Interface_load
|
@@ -301,16 +302,18 @@ def load_gallery(gallery,id):
|
|
301 |
def load_gallery_actu(gallery,id):
|
302 |
gallery = reset_gallery(gallery)
|
303 |
#for c in cache_image_actu:
|
304 |
-
for c in
|
305 |
gallery=add_gallery(c[0],c[1],gallery)
|
306 |
return gallery
|
307 |
|
308 |
-
def add_cache_image(
|
309 |
-
|
|
|
310 |
#cache_image=sorted(cache_image, key=itemgetter(1))
|
311 |
return
|
312 |
-
def add_cache_image_actu(
|
313 |
-
|
|
|
314 |
#cache_image_actu=sorted(cache_image_actu, key=itemgetter(1))
|
315 |
return
|
316 |
def reset_cache_image(id,cache_image=cache_image):
|
@@ -377,6 +380,24 @@ def search_info(txt_search_info,models_plus_tags=models_plus_tags):
|
|
377 |
outputList.append("Model Not Find")
|
378 |
return gr.Textbox(label="out",value=outputList)
|
379 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
380 |
|
381 |
def make_me():
|
382 |
# with gr.Tab('The Dream'):
|
@@ -391,6 +412,11 @@ def make_me():
|
|
391 |
with gr.Row():
|
392 |
width = gr.Slider(label="Width", info="If 0, the default value is used.", maximum=1216, step=32, value=0)
|
393 |
height = gr.Slider(label="Height", info="If 0, the default value is used.", maximum=1216, step=32, value=0)
|
|
|
|
|
|
|
|
|
|
|
394 |
with gr.Row():
|
395 |
steps = gr.Slider(label="Number of inference steps", info="If 0, the default value is used.", maximum=100, step=1, value=0)
|
396 |
cfg = gr.Slider(label="Guidance scale", info="If 0, the default value is used.", maximum=30.0, step=0.1, value=0)
|
@@ -414,13 +440,11 @@ def make_me():
|
|
414 |
choices=models_test[0][1][0][1]
|
415 |
"""output = [gr.Image(label=m, min_width=170, height=170) for m in choices]
|
416 |
current_models = [gr.Textbox(m, visible=False) for m in choices]"""
|
417 |
-
|
418 |
-
|
419 |
-
output_g = update_imgbox([choices[0]])
|
420 |
-
current_models_g = extend_choices_b([choices[0]])
|
421 |
|
422 |
|
423 |
-
for m, o in zip(
|
424 |
gen_event = gr.on(triggers=[gen_button.click, txt_input.submit], fn=gen_fn,
|
425 |
inputs=[m, txt_input, neg_input, height, width, steps, cfg, seed], outputs=[o])
|
426 |
stop_button.click(lambda: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
|
@@ -439,7 +463,6 @@ def make_me():
|
|
439 |
gen_button.click(set_session, id_session, id_session)
|
440 |
cache_image[f"{id_session.value}"]=[]
|
441 |
cache_image_actu[f"{id_session.value}"]=[]
|
442 |
-
print(cache_image)
|
443 |
with gr.Column():
|
444 |
b11 = gr.Button('Load Galerry Actu')
|
445 |
b12 = gr.Button('Load Galerry All')
|
@@ -453,7 +476,7 @@ def make_me():
|
|
453 |
b12.click(load_gallery,[gallery,id_session],gallery)
|
454 |
b21.click(reset_gallery,[gallery],gallery)
|
455 |
b22.click(reset_cache_image,[id_session],gallery)
|
456 |
-
for m, o in zip(
|
457 |
#o.change(add_gallery, [o, m, gallery], [gallery])
|
458 |
o.change(add_cache_image,[o,m,id_session],[])
|
459 |
o.change(add_cache_image_actu,[o,m,id_session],[])
|
@@ -465,8 +488,8 @@ def make_me():
|
|
465 |
|
466 |
with gr.Row():
|
467 |
group_model_choice = gr.Dropdown(label="List of Models with the chosen Tag", show_label=True, choices=list([]) , interactive = True)
|
468 |
-
group_model_choice.change(choice_group_b,group_model_choice,
|
469 |
-
group_model_choice.change(choice_group_c,group_model_choice,
|
470 |
group_tag_choice.change(tag_choice,group_tag_choice,group_model_choice)
|
471 |
|
472 |
with gr.Row():
|
@@ -477,8 +500,8 @@ def make_me():
|
|
477 |
txt_list_perso = gr.Textbox(label='List Models Perso')
|
478 |
|
479 |
button_list_perso = gr.Button('Load')
|
480 |
-
button_list_perso.click(aff_models_perso_b,txt_list_perso,
|
481 |
-
button_list_perso.click(aff_models_perso_c,txt_list_perso,
|
482 |
|
483 |
with gr.Row():
|
484 |
txt_search = gr.Textbox(label='Search in')
|
|
|
2 |
import gradio as gr
|
3 |
from random import randint
|
4 |
from operator import itemgetter
|
5 |
+
import bisect
|
6 |
from all_models import tags_plus_models,models,models_plus_tags
|
7 |
from datetime import datetime
|
8 |
from externalmod import gr_Interface_load
|
|
|
302 |
def load_gallery_actu(gallery,id):
|
303 |
gallery = reset_gallery(gallery)
|
304 |
#for c in cache_image_actu:
|
305 |
+
for c in cache_image_actu[f"{id}"]:
|
306 |
gallery=add_gallery(c[0],c[1],gallery)
|
307 |
return gallery
|
308 |
|
309 |
+
def add_cache_image(image, model_str,id,cache_image=cache_image):
|
310 |
+
if image is not None:
|
311 |
+
cache_image[f"{id}"].append((image,model_str))
|
312 |
#cache_image=sorted(cache_image, key=itemgetter(1))
|
313 |
return
|
314 |
+
def add_cache_image_actu(image, model_str,id,cache_image_actu=cache_image_actu):
|
315 |
+
if image is not None:
|
316 |
+
bisect.insort(cache_image_actu[f"{id}"],(image, model_str), key=itemgetter(1))
|
317 |
#cache_image_actu=sorted(cache_image_actu, key=itemgetter(1))
|
318 |
return
|
319 |
def reset_cache_image(id,cache_image=cache_image):
|
|
|
380 |
outputList.append("Model Not Find")
|
381 |
return gr.Textbox(label="out",value=outputList)
|
382 |
|
383 |
+
def ratio_chosen(choice_ratio,width,height):
|
384 |
+
if choice_ratio == [None,None]:
|
385 |
+
return width , height
|
386 |
+
else :
|
387 |
+
return gr.Slider(label="Width", info="If 0, the default value is used.", maximum=2024, step=32, value=choice_ratio[0]), gr.Slider(label="Height", info="If 0, the default value is used.", maximum=2024, step=32, value=choice_ratio[1])
|
388 |
+
|
389 |
+
list_ratios=[["None",[None,None]],
|
390 |
+
["4:1 (2048 x 512)",[2048,512]],
|
391 |
+
["12:5 (1536 x 640)",[1536,640]],
|
392 |
+
["~16:9 (1344 x 768)",[1344,768]],
|
393 |
+
["~3:2 (1216 x 832)",[1216,832]],
|
394 |
+
["~4:3 (1152 x 896)",[1152,896]],
|
395 |
+
["1:1 (1024 x 1024)",[1024,1024]],
|
396 |
+
["~3:4 (896 x 1152)",[896,1152]],
|
397 |
+
["~2:3 (832 x 1216)",[832,1216]],
|
398 |
+
["~9:16 (768 x 1344)",[768,1344]],
|
399 |
+
["5:12 (640 x 1536)",[640,1536]],
|
400 |
+
["1:4 (512 x 2048)",[512,2048]]]
|
401 |
|
402 |
def make_me():
|
403 |
# with gr.Tab('The Dream'):
|
|
|
412 |
with gr.Row():
|
413 |
width = gr.Slider(label="Width", info="If 0, the default value is used.", maximum=1216, step=32, value=0)
|
414 |
height = gr.Slider(label="Height", info="If 0, the default value is used.", maximum=1216, step=32, value=0)
|
415 |
+
with gr.Row():
|
416 |
+
choice_ratio = gr.Dropdown(label="Ratio Width/Height",
|
417 |
+
info="OverWrite Width and Height (W*H<1024*1024)",
|
418 |
+
show_label=True, choices=list(list_ratios) , interactive = True, value=list_ratios[0])
|
419 |
+
choice_ratio.change(ratio_chosen,[choice_ratio,width,height],[width,height])
|
420 |
with gr.Row():
|
421 |
steps = gr.Slider(label="Number of inference steps", info="If 0, the default value is used.", maximum=100, step=1, value=0)
|
422 |
cfg = gr.Slider(label="Guidance scale", info="If 0, the default value is used.", maximum=30.0, step=0.1, value=0)
|
|
|
440 |
choices=models_test[0][1][0][1]
|
441 |
"""output = [gr.Image(label=m, min_width=170, height=170) for m in choices]
|
442 |
current_models = [gr.Textbox(m, visible=False) for m in choices]"""
|
443 |
+
output = update_imgbox([choices[0]])
|
444 |
+
current_models = extend_choices_b([choices[0]])
|
|
|
|
|
445 |
|
446 |
|
447 |
+
for m, o in zip(current_models, output):
|
448 |
gen_event = gr.on(triggers=[gen_button.click, txt_input.submit], fn=gen_fn,
|
449 |
inputs=[m, txt_input, neg_input, height, width, steps, cfg, seed], outputs=[o])
|
450 |
stop_button.click(lambda: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
|
|
|
463 |
gen_button.click(set_session, id_session, id_session)
|
464 |
cache_image[f"{id_session.value}"]=[]
|
465 |
cache_image_actu[f"{id_session.value}"]=[]
|
|
|
466 |
with gr.Column():
|
467 |
b11 = gr.Button('Load Galerry Actu')
|
468 |
b12 = gr.Button('Load Galerry All')
|
|
|
476 |
b12.click(load_gallery,[gallery,id_session],gallery)
|
477 |
b21.click(reset_gallery,[gallery],gallery)
|
478 |
b22.click(reset_cache_image,[id_session],gallery)
|
479 |
+
for m, o in zip(current_models, output):
|
480 |
#o.change(add_gallery, [o, m, gallery], [gallery])
|
481 |
o.change(add_cache_image,[o,m,id_session],[])
|
482 |
o.change(add_cache_image_actu,[o,m,id_session],[])
|
|
|
488 |
|
489 |
with gr.Row():
|
490 |
group_model_choice = gr.Dropdown(label="List of Models with the chosen Tag", show_label=True, choices=list([]) , interactive = True)
|
491 |
+
group_model_choice.change(choice_group_b,group_model_choice,output)
|
492 |
+
group_model_choice.change(choice_group_c,group_model_choice,current_models)
|
493 |
group_tag_choice.change(tag_choice,group_tag_choice,group_model_choice)
|
494 |
|
495 |
with gr.Row():
|
|
|
500 |
txt_list_perso = gr.Textbox(label='List Models Perso')
|
501 |
|
502 |
button_list_perso = gr.Button('Load')
|
503 |
+
button_list_perso.click(aff_models_perso_b,txt_list_perso,output)
|
504 |
+
button_list_perso.click(aff_models_perso_c,txt_list_perso,current_models)
|
505 |
|
506 |
with gr.Row():
|
507 |
txt_search = gr.Textbox(label='Search in')
|