Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,7 @@ HF_TOKEN = os.environ.get("HF_TOKEN") if os.environ.get("HF_TOKEN") else None #
|
|
| 14 |
|
| 15 |
|
| 16 |
nb_req_simult=50 ########
|
|
|
|
| 17 |
|
| 18 |
now2 = 0
|
| 19 |
inference_timeout = 300
|
|
@@ -296,11 +297,13 @@ def fonc_load_info_custom(nb_of_models_to_gen,list_model_custom,index_first_mode
|
|
| 296 |
def crea_list_task(id_session,list_param,list_models_to_gen,nb_images_by_prompt):
|
| 297 |
cache_list_task[f"{id_session}"]=[]
|
| 298 |
dict_temp={}
|
|
|
|
| 299 |
for m in list_models_to_gen:
|
| 300 |
dict_temp={}
|
| 301 |
dict_temp["model"]=m
|
| 302 |
dict_temp["id_module"]=-1
|
| 303 |
dict_temp["task"]=[]
|
|
|
|
| 304 |
for p in list_param:
|
| 305 |
for i in range(nb_images_by_prompt):
|
| 306 |
dict_temp["task"].append({"prompt":p[0],"nprompt":p[1],"width":p[2],"height":p[3],"steps":p[4],"cfg":p[5],"seed":p[6]})
|
|
@@ -309,12 +312,20 @@ def crea_list_task(id_session,list_param,list_models_to_gen,nb_images_by_prompt)
|
|
| 309 |
cache_text_actu[f"{id_session}"]={"nb_modules_use":nb_req_simult,"stop":False,"nb_fail":0,
|
| 310 |
"nb_models_to_do":len(list_models_to_gen) ,"nb_models_tot":len(list_models_to_gen) ,
|
| 311 |
"nb_tasks_to_do":len(list_models_to_gen)*len(list_param)*nb_images_by_prompt ,
|
| 312 |
-
"nb_tasks_tot":len(list_models_to_gen)*len(list_param)*nb_images_by_prompt
|
|
|
|
| 313 |
|
| 314 |
def fonc_update_actu(text_actu,id):
|
| 315 |
s=""
|
| 316 |
s+=f"modules: {cache_text_actu[str(id)]['nb_modules_use']}/{nb_req_simult}\n"
|
| 317 |
s+=f"models remaining: {cache_text_actu[str(id)]['nb_models_to_do']}/{cache_text_actu[str(id)]['nb_models_tot']}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
s+=f"images remaining: {cache_text_actu[str(id)]['nb_tasks_to_do']}/{cache_text_actu[str(id)]['nb_tasks_tot']}\n"
|
| 319 |
s+=f"fail attempt: {cache_text_actu[str(id)]['nb_fail']}"
|
| 320 |
return gr.Textbox(s)
|
|
@@ -355,15 +366,25 @@ def fonc_load_gallery(id_session,gallery):
|
|
| 355 |
gallery = reset_gallery(gallery)
|
| 356 |
for i in range(len(cache_image[f"{id_session}"])):
|
| 357 |
gallery=add_gallery(cache_image[f"{id_session}"][i]["image"],cache_image[f"{id_session}"][i]["model"],gallery)
|
| 358 |
-
return gallery
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
|
| 366 |
-
def fonc_start(id_session,id_module,s,cont):
|
| 367 |
if cont==False:
|
| 368 |
cache_text_actu[f"{id_session}"]["nb_modules_use"]-=1
|
| 369 |
print("manual stop")
|
|
@@ -386,6 +407,12 @@ def fonc_start(id_session,id_module,s,cont):
|
|
| 386 |
model_actu=model_plus_tasks["model"]
|
| 387 |
task_actu=model_plus_tasks["task"][0]
|
| 388 |
print(f"module num {id_module} take {model_actu}\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
if model_actu=="":
|
| 390 |
cache_text_actu[f"{id_session}"]["nb_modules_use"]-=1
|
| 391 |
print("Stop with :"+s+"\n")
|
|
@@ -398,13 +425,20 @@ def fonc_start(id_session,id_module,s,cont):
|
|
| 398 |
if result!=None:
|
| 399 |
#result=gr.Image(result)
|
| 400 |
id_image=len(cache_image[f"{id_session}"])
|
|
|
|
| 401 |
for model_plus_tasks in cache_list_task[f"{id_session}"]:
|
| 402 |
if model_plus_tasks["id_module"]==id_module:
|
| 403 |
model_plus_tasks["task"].remove(task_actu)
|
| 404 |
cache_text_actu[f"{id_session}"]["nb_tasks_to_do"]-=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
if len(model_plus_tasks["task"])==0:
|
| 406 |
cache_list_task[f"{id_session}"].remove(model_plus_tasks)
|
| 407 |
cache_text_actu[f"{id_session}"]["nb_models_to_do"]-=1
|
|
|
|
| 408 |
|
| 409 |
task_actu["id_image"]=id_image
|
| 410 |
task_actu["model"]=model_actu
|
|
@@ -426,17 +460,23 @@ def fonc_start(id_session,id_module,s,cont):
|
|
| 426 |
def fonc_init(s):
|
| 427 |
return gr.Textbox(s+"1")
|
| 428 |
|
| 429 |
-
def
|
| 430 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
def index_gallery_next(i,list_models):
|
| 432 |
iT=i+1
|
| 433 |
-
return gr.Number(iT%len(list_models))
|
| 434 |
def index_gallery_prev(i,list_models):
|
| 435 |
iT=i-1
|
| 436 |
-
return gr.Number(iT%len(list_models))
|
| 437 |
|
| 438 |
def change_text_model_actu_gal(list_models,index):
|
| 439 |
-
return gr.Textbox(f"{list_models[index]}")
|
| 440 |
def fonc_add_to_text(text,list_models,index):
|
| 441 |
return gr.Textbox(text+f"\"{list_models[index]}\",\n")
|
| 442 |
|
|
@@ -548,6 +588,7 @@ def make_me():
|
|
| 548 |
text_actu=gr.Textbox("",label="in progress",interactive=False,lines=6)
|
| 549 |
update_actu=gr.Number(0,visible=False)
|
| 550 |
update_actu.change(fonc_update_actu,[text_actu,id_session],[text_actu])
|
|
|
|
| 551 |
with gr.Row():
|
| 552 |
outputs=[]
|
| 553 |
id_modules=[]
|
|
@@ -561,40 +602,52 @@ def make_me():
|
|
| 561 |
for o,i,s in zip(outputs,id_modules,states):
|
| 562 |
#o.change(fonc_start,[id_session,i],[o])
|
| 563 |
#o.change(test_change,[],[])
|
| 564 |
-
s.change(fonc_start,[id_session,i,s,cont],[o,s,update_actu])
|
| 565 |
#button_start.click(lambda : gr.Image(None),[],[o])
|
| 566 |
gen_event = gr.on(triggers=[button_start.click], fn=fonc_init,inputs=[s], outputs=[s])
|
| 567 |
|
| 568 |
with gr.Column(scale=2):
|
| 569 |
gallery = gr.Gallery(label="Output", show_download_button=True, elem_classes="gallery",
|
| 570 |
interactive=False, show_share_button=True, container=True, format="png",
|
| 571 |
-
preview=True, object_fit="cover",columns=4,rows=4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
with gr.Column(scale=3):
|
| 573 |
button_load_gallery=gr.Button("Load Gallery All")
|
| 574 |
button_load_gallery.click(fonc_load_gallery,[id_session,gallery],[gallery])
|
| 575 |
|
| 576 |
-
|
| 577 |
-
button_load_gallery_first=gr.Button("
|
| 578 |
-
button_load_gallery_first.click(index_gallery_first,[],[index_gallery])
|
| 579 |
with gr.Row():
|
| 580 |
button_load_gallery_prev=gr.Button("Prev model")
|
| 581 |
button_load_gallery_next=gr.Button("Next model")
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 585 |
text_model_actu_gal = gr.Textbox(label='Model Actu:', lines=1, interactive = False)
|
| 586 |
-
|
| 587 |
with gr.Row():
|
| 588 |
with gr.Column():
|
| 589 |
button_add_to_bl=gr.Button("Add to Blacklist")
|
| 590 |
#button_remove_from_bl=gr.Button("Remove from Blacklist")
|
| 591 |
text_bl=gr.Textbox(label='Blacklist', lines=5, interactive = True)
|
| 592 |
-
button_add_to_bl.click(fonc_add_to_text,[text_bl,list_models_to_gen,
|
| 593 |
-
#button_remove_from_bl.click(fonc_remove_from_text,[text_bl,list_models_to_gen,
|
| 594 |
with gr.Column():
|
| 595 |
button_add_to_fav=gr.Button("Add to Favlist")
|
| 596 |
text_fav=gr.Textbox(label='Favlist', lines=5, interactive = True)
|
| 597 |
-
button_add_to_fav.click(fonc_add_to_text,[text_fav,list_models_to_gen,
|
| 598 |
|
| 599 |
|
| 600 |
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
nb_req_simult=50 ########
|
| 17 |
+
nb_gallery_model=5
|
| 18 |
|
| 19 |
now2 = 0
|
| 20 |
inference_timeout = 300
|
|
|
|
| 297 |
def crea_list_task(id_session,list_param,list_models_to_gen,nb_images_by_prompt):
|
| 298 |
cache_list_task[f"{id_session}"]=[]
|
| 299 |
dict_temp={}
|
| 300 |
+
list_progress=[]
|
| 301 |
for m in list_models_to_gen:
|
| 302 |
dict_temp={}
|
| 303 |
dict_temp["model"]=m
|
| 304 |
dict_temp["id_module"]=-1
|
| 305 |
dict_temp["task"]=[]
|
| 306 |
+
list_progress.append(0)
|
| 307 |
for p in list_param:
|
| 308 |
for i in range(nb_images_by_prompt):
|
| 309 |
dict_temp["task"].append({"prompt":p[0],"nprompt":p[1],"width":p[2],"height":p[3],"steps":p[4],"cfg":p[5],"seed":p[6]})
|
|
|
|
| 312 |
cache_text_actu[f"{id_session}"]={"nb_modules_use":nb_req_simult,"stop":False,"nb_fail":0,
|
| 313 |
"nb_models_to_do":len(list_models_to_gen) ,"nb_models_tot":len(list_models_to_gen) ,
|
| 314 |
"nb_tasks_to_do":len(list_models_to_gen)*len(list_param)*nb_images_by_prompt ,
|
| 315 |
+
"nb_tasks_tot":len(list_models_to_gen)*len(list_param)*nb_images_by_prompt,
|
| 316 |
+
"progress":list_progress,'nb_tasks_by_model': nb_images_by_prompt*len(list_param) }
|
| 317 |
|
| 318 |
def fonc_update_actu(text_actu,id):
|
| 319 |
s=""
|
| 320 |
s+=f"modules: {cache_text_actu[str(id)]['nb_modules_use']}/{nb_req_simult}\n"
|
| 321 |
s+=f"models remaining: {cache_text_actu[str(id)]['nb_models_to_do']}/{cache_text_actu[str(id)]['nb_models_tot']}\n"
|
| 322 |
+
i=0
|
| 323 |
+
for d in cache_text_actu[str(id)]['progress']:
|
| 324 |
+
i+=1
|
| 325 |
+
s+=str(d)
|
| 326 |
+
if i%10==0:
|
| 327 |
+
s+=" "
|
| 328 |
+
s+="\n"
|
| 329 |
s+=f"images remaining: {cache_text_actu[str(id)]['nb_tasks_to_do']}/{cache_text_actu[str(id)]['nb_tasks_tot']}\n"
|
| 330 |
s+=f"fail attempt: {cache_text_actu[str(id)]['nb_fail']}"
|
| 331 |
return gr.Textbox(s)
|
|
|
|
| 366 |
gallery = reset_gallery(gallery)
|
| 367 |
for i in range(len(cache_image[f"{id_session}"])):
|
| 368 |
gallery=add_gallery(cache_image[f"{id_session}"][i]["image"],cache_image[f"{id_session}"][i]["model"],gallery)
|
| 369 |
+
return gr.Gallery(gallery,visible=True)
|
| 370 |
+
|
| 371 |
+
def fonc_move_gallery_by_model(id_session,gallery,index_g,models,index_m,direction):
|
| 372 |
+
delta=int((nb_gallery_model-1)/2)
|
| 373 |
+
if index_g==(index_m+(delta*direction))%nb_gallery_model :
|
| 374 |
+
gallery = reset_gallery(gallery)
|
| 375 |
+
for i in range(len(cache_image[f"{id_session}"])):
|
| 376 |
+
if cache_image[f"{id_session}"][i]["model"]==models[(index_m+(delta*direction))%len(models)]:
|
| 377 |
+
gallery=add_gallery(cache_image[f"{id_session}"][i]["image"],cache_image[f"{id_session}"][i]["model"],gallery)
|
| 378 |
+
if index_g==(index_m-direction)%nb_gallery_model:
|
| 379 |
+
return gr.Gallery(gallery,visible=False)
|
| 380 |
+
#return gr.Gallery(gallery,visible=True)
|
| 381 |
+
elif index_g==index_m%nb_gallery_model:
|
| 382 |
+
return gr.Gallery(gallery,visible=True)
|
| 383 |
+
else:
|
| 384 |
+
return gallery
|
| 385 |
+
|
| 386 |
|
| 387 |
+
def fonc_start(id_session,id_module,s,cont,list_models_to_gen):
|
| 388 |
if cont==False:
|
| 389 |
cache_text_actu[f"{id_session}"]["nb_modules_use"]-=1
|
| 390 |
print("manual stop")
|
|
|
|
| 407 |
model_actu=model_plus_tasks["model"]
|
| 408 |
task_actu=model_plus_tasks["task"][0]
|
| 409 |
print(f"module num {id_module} take {model_actu}\n")
|
| 410 |
+
i=0
|
| 411 |
+
for model in list_models_to_gen:
|
| 412 |
+
if model_actu==model:
|
| 413 |
+
cache_text_actu[f"{id_session}"]['progress'][i]=1
|
| 414 |
+
i+=1
|
| 415 |
+
|
| 416 |
if model_actu=="":
|
| 417 |
cache_text_actu[f"{id_session}"]["nb_modules_use"]-=1
|
| 418 |
print("Stop with :"+s+"\n")
|
|
|
|
| 425 |
if result!=None:
|
| 426 |
#result=gr.Image(result)
|
| 427 |
id_image=len(cache_image[f"{id_session}"])
|
| 428 |
+
i=0
|
| 429 |
for model_plus_tasks in cache_list_task[f"{id_session}"]:
|
| 430 |
if model_plus_tasks["id_module"]==id_module:
|
| 431 |
model_plus_tasks["task"].remove(task_actu)
|
| 432 |
cache_text_actu[f"{id_session}"]["nb_tasks_to_do"]-=1
|
| 433 |
+
i=0
|
| 434 |
+
for model in list_models_to_gen:
|
| 435 |
+
if model_actu==model:
|
| 436 |
+
cache_text_actu[f"{id_session}"]['progress'][i]=int(((1-(len(model_plus_tasks["task"])/cache_text_actu[f"{id_session}"]["nb_tasks_by_model"]))*8)//1)+1
|
| 437 |
+
i+=1
|
| 438 |
if len(model_plus_tasks["task"])==0:
|
| 439 |
cache_list_task[f"{id_session}"].remove(model_plus_tasks)
|
| 440 |
cache_text_actu[f"{id_session}"]["nb_models_to_do"]-=1
|
| 441 |
+
|
| 442 |
|
| 443 |
task_actu["id_image"]=id_image
|
| 444 |
task_actu["model"]=model_actu
|
|
|
|
| 460 |
def fonc_init(s):
|
| 461 |
return gr.Textbox(s+"1")
|
| 462 |
|
| 463 |
+
def fonc_load_gallery_by_model(id_session,gallery,models,index_g,index_m,gallery_all):
|
| 464 |
+
delta=int((nb_gallery_model-1)/2)
|
| 465 |
+
gallery = reset_gallery(gallery)
|
| 466 |
+
for i in range(len(cache_image[f"{id_session}"])):
|
| 467 |
+
if cache_image[f"{id_session}"][i]["model"]==models[((index_m+index_g+delta)%nb_gallery_model)-delta]:
|
| 468 |
+
gallery=add_gallery(cache_image[f"{id_session}"][i]["image"],cache_image[f"{id_session}"][i]["model"],gallery)
|
| 469 |
+
return gr.Gallery(gallery,visible=(index_g==(index_m%nb_gallery_model))), gr.Gallery(gallery_all,visible=False)#################################
|
| 470 |
+
#return gr.Gallery(gallery,visible=True), gr.Gallery(gallery_all,visible=False)
|
| 471 |
def index_gallery_next(i,list_models):
|
| 472 |
iT=i+1
|
| 473 |
+
return gr.Number(iT%len(list_models)),gr.Number(1)
|
| 474 |
def index_gallery_prev(i,list_models):
|
| 475 |
iT=i-1
|
| 476 |
+
return gr.Number(iT%len(list_models)),gr.Number(-1)
|
| 477 |
|
| 478 |
def change_text_model_actu_gal(list_models,index):
|
| 479 |
+
return gr.Textbox(f"({(index%(len(list_models)))+1}/{(len(list_models))}) {list_models[index]}")
|
| 480 |
def fonc_add_to_text(text,list_models,index):
|
| 481 |
return gr.Textbox(text+f"\"{list_models[index]}\",\n")
|
| 482 |
|
|
|
|
| 588 |
text_actu=gr.Textbox("",label="in progress",interactive=False,lines=6)
|
| 589 |
update_actu=gr.Number(0,visible=False)
|
| 590 |
update_actu.change(fonc_update_actu,[text_actu,id_session],[text_actu])
|
| 591 |
+
button_start.click(fonc_update_actu,[text_actu,id_session],[text_actu])
|
| 592 |
with gr.Row():
|
| 593 |
outputs=[]
|
| 594 |
id_modules=[]
|
|
|
|
| 602 |
for o,i,s in zip(outputs,id_modules,states):
|
| 603 |
#o.change(fonc_start,[id_session,i],[o])
|
| 604 |
#o.change(test_change,[],[])
|
| 605 |
+
s.change(fonc_start,[id_session,i,s,cont,list_models_to_gen],[o,s,update_actu])
|
| 606 |
#button_start.click(lambda : gr.Image(None),[],[o])
|
| 607 |
gen_event = gr.on(triggers=[button_start.click], fn=fonc_init,inputs=[s], outputs=[s])
|
| 608 |
|
| 609 |
with gr.Column(scale=2):
|
| 610 |
gallery = gr.Gallery(label="Output", show_download_button=True, elem_classes="gallery",
|
| 611 |
interactive=False, show_share_button=True, container=True, format="png",
|
| 612 |
+
preview=True, object_fit="cover",columns=4,rows=4)
|
| 613 |
+
gallery_models=[]
|
| 614 |
+
index_gallery=[]
|
| 615 |
+
for i in range(nb_gallery_model):
|
| 616 |
+
gallery_models.append(gr.Gallery(label="Output", show_download_button=True, elem_classes="gallery",
|
| 617 |
+
interactive=False, show_share_button=True, container=True, format="png",
|
| 618 |
+
preview=True, object_fit="cover",columns=4,rows=4,visible=False))
|
| 619 |
+
index_gallery.append(gr.Number(i,visible=False))
|
| 620 |
with gr.Column(scale=3):
|
| 621 |
button_load_gallery=gr.Button("Load Gallery All")
|
| 622 |
button_load_gallery.click(fonc_load_gallery,[id_session,gallery],[gallery])
|
| 623 |
|
| 624 |
+
index_gallery_m=gr.Number(0,visible=False)
|
| 625 |
+
button_load_gallery_first=gr.Button("Init Gallery by model")
|
|
|
|
| 626 |
with gr.Row():
|
| 627 |
button_load_gallery_prev=gr.Button("Prev model")
|
| 628 |
button_load_gallery_next=gr.Button("Next model")
|
| 629 |
+
direction_gallery=gr.Number(0,visible=False)
|
| 630 |
+
button_load_gallery_next.click(index_gallery_next,[index_gallery_m,list_models_to_gen],[index_gallery_m,direction_gallery])
|
| 631 |
+
button_load_gallery_prev.click(index_gallery_prev,[index_gallery_m,list_models_to_gen],[index_gallery_m,direction_gallery])
|
| 632 |
+
for g,i in zip(gallery_models,index_gallery):
|
| 633 |
+
index_gallery_m.change(fonc_move_gallery_by_model,[id_session,g,i,list_models_to_gen,index_gallery_m,direction_gallery],[g])
|
| 634 |
+
gen_event_gallery_first = gr.on(triggers=[button_load_gallery_first.click], fn=fonc_load_gallery_by_model,
|
| 635 |
+
inputs=[id_session,g,list_models_to_gen,i,index_gallery_m,gallery], outputs=[g,gallery])
|
| 636 |
+
gen_event_gallery_first_all = gr.on(triggers=[button_load_gallery.click], fn=lambda g:gr.Gallery(g,visible=False),
|
| 637 |
+
inputs=[g], outputs=[g])
|
| 638 |
text_model_actu_gal = gr.Textbox(label='Model Actu:', lines=1, interactive = False)
|
| 639 |
+
index_gallery_m.change(change_text_model_actu_gal,[list_models_to_gen,index_gallery_m],[text_model_actu_gal])
|
| 640 |
with gr.Row():
|
| 641 |
with gr.Column():
|
| 642 |
button_add_to_bl=gr.Button("Add to Blacklist")
|
| 643 |
#button_remove_from_bl=gr.Button("Remove from Blacklist")
|
| 644 |
text_bl=gr.Textbox(label='Blacklist', lines=5, interactive = True)
|
| 645 |
+
button_add_to_bl.click(fonc_add_to_text,[text_bl,list_models_to_gen,index_gallery_m],[text_bl])
|
| 646 |
+
#button_remove_from_bl.click(fonc_remove_from_text,[text_bl,list_models_to_gen,index_gallery_m],[text_bl])
|
| 647 |
with gr.Column():
|
| 648 |
button_add_to_fav=gr.Button("Add to Favlist")
|
| 649 |
text_fav=gr.Textbox(label='Favlist', lines=5, interactive = True)
|
| 650 |
+
button_add_to_fav.click(fonc_add_to_text,[text_fav,list_models_to_gen,index_gallery_m],[text_fav])
|
| 651 |
|
| 652 |
|
| 653 |
|