DemiPoto commited on
Commit
101951c
1 Parent(s): b205d6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -11
app.py CHANGED
@@ -13,7 +13,7 @@ lock = RLock()
13
  HF_TOKEN = os.environ.get("HF_TOKEN") if os.environ.get("HF_TOKEN") else None # If private or gated models aren't used, ENV setting is unnecessary.
14
 
15
 
16
- nb_req_simult=50 ########
17
  nb_gallery_model=5
18
 
19
  now2 = 0
@@ -29,6 +29,7 @@ cache_image={}
29
  cache_id_image={}
30
  cache_list_task={}
31
  cache_text_actu={}
 
32
 
33
 
34
  def load_fn(models):
@@ -169,19 +170,40 @@ def set_session(id):
169
 
170
  cache_list_task[f"{randTemp}"]=[]
171
  cache_text_actu[f"{randTemp}"]={}
 
172
  return gr.Number(visible=False,value=randTemp)
173
  else :
174
  return id
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  def print_info_sessions():
176
  lenTot=0
177
- print("###################################")
178
- print("number of sessions : "+str(len(cache_image)))
179
  for key, listT in cache_image.items():
180
- print("session "+key+" : "+str(len(listT)))
181
  lenTot+=len(listT)
182
- print("images total = "+str(lenTot))
183
- print("###################################")
184
- return
185
 
186
  def disp_models(group_model_choice,nb_rep=nb_rep):
187
  listTemp=[]
@@ -298,6 +320,9 @@ def fonc_load_info_custom(nb_of_models_to_gen,list_model_custom,index_first_mode
298
  return nb_of_models_to_gen,gr.Textbox(str_temp),gr.Dropdown(choices=[["",list_models_temp]], value=list_models_temp )
299
 
300
  def crea_list_task(id_session,list_param,list_models_to_gen,nb_images_by_prompt):
 
 
 
301
  cache_list_task[f"{id_session}"]=[]
302
  dict_temp={}
303
  list_progress=[]
@@ -436,7 +461,7 @@ def fonc_start(id_session,id_module,s,cont,list_models_to_gen):
436
  i=0
437
  for model in list_models_to_gen:
438
  if model_actu==model:
439
- 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
440
  i+=1
441
  if len(model_plus_tasks["task"])==0:
442
  cache_list_task[f"{id_session}"].remove(model_plus_tasks)
@@ -519,7 +544,6 @@ def make_me():
519
  with gr.Tab(" Sort ",visible=False) as tab_p:
520
  button_test_pass.click(test_pass_aff,[test_pass],[tab_p])
521
  with gr.Column():
522
- id_session=gr.Number(visible=False,value=0)
523
  with gr.Group():
524
  with gr.Row():
525
  with gr.Column(scale=4):
@@ -553,10 +577,24 @@ def make_me():
553
  inputs=[txt_input,neg_input,width,height,steps,cfg,seed],
554
  outputs=[txt_input,neg_input,width,height,steps,cfg,seed],
555
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
556
  add_param.click(fonc_add_param,[list_param,txt_input,neg_input,width,height,steps,cfg,seed],[disp_param.dataset,list_param])
557
  add_param.click(set_session,[id_session],[id_session])
558
  del_param.click(fonc_del_param,[list_param,txt_input,neg_input,width,height,steps,cfg,seed],[disp_param.dataset,list_param])
559
-
560
  with gr.Row():
561
  list_models_to_gen=gr.Dropdown(choices=[["",[]]], value=[], visible=False)
562
  disp_info=gr.Textbox(label="Info")
@@ -586,7 +624,6 @@ def make_me():
586
 
587
  load_model_custom=gr.Button("Load Models Custom")
588
  load_model_custom.click(fonc_load_info_custom,[nb_of_models_to_gen,list_model_custom,index_first_model_custom],[nb_of_models_to_gen,disp_info,list_models_to_gen])
589
-
590
  list_models_to_gen.change(crea_list_task,[id_session,list_param,list_models_to_gen,nb_images_by_prompt],[])
591
 
592
 
@@ -720,8 +757,11 @@ def make_me():
720
 
721
 
722
 
 
723
 
724
 
 
 
725
  js_code = """
726
 
727
  console.log('ghgh');
 
13
  HF_TOKEN = os.environ.get("HF_TOKEN") if os.environ.get("HF_TOKEN") else None # If private or gated models aren't used, ENV setting is unnecessary.
14
 
15
 
16
+ nb_req_simult=80 ########
17
  nb_gallery_model=5
18
 
19
  now2 = 0
 
29
  cache_id_image={}
30
  cache_list_task={}
31
  cache_text_actu={}
32
+ from_reload={}
33
 
34
 
35
  def load_fn(models):
 
170
 
171
  cache_list_task[f"{randTemp}"]=[]
172
  cache_text_actu[f"{randTemp}"]={}
173
+ from_reload[f"{randTemp}"]=False
174
  return gr.Number(visible=False,value=randTemp)
175
  else :
176
  return id
177
+
178
+ def fonc_restore_session(id):
179
+ from_reload[f"{id}"]=True
180
+ list_param=[]
181
+ list_models=[]
182
+ for m in cache_list_task[f"{id}"]:
183
+ if m["model"] not in list_models:
184
+ list_models.append(m["model"])
185
+ for t in m["task"]:
186
+ if [t["prompt"],t["nprompt"],t["width"],t["height"],t["steps"],t["cfg"],t["seed"]] not in list_param:
187
+ list_param.append([t["prompt"],t["nprompt"],t["width"],t["height"],t["steps"],t["cfg"],t["seed"]])
188
+ for t in cache_image[f"{id}"]:
189
+ if t["model"] not in list_models :
190
+ list_models.append(t["model"])
191
+ if [t["prompt"],t["nprompt"],t["width"],t["height"],t["steps"],t["cfg"],t["seed"]] not in list_param:
192
+ list_param.append([t["prompt"],t["nprompt"],t["width"],t["height"],t["steps"],t["cfg"],t["seed"]])
193
+
194
+ cache_text_actu[f"{id}"]["nb_modules_use"]=nb_req_simult
195
+ cache_text_actu[f"{id}"]["stop"]=False
196
+ return gr.Dropdown(choices=[["a",list_param]], value=list_param) ,gr.Dataset(samples=list_param), list_models , len(list_models)
197
+
198
  def print_info_sessions():
199
  lenTot=0
200
+ s=""
201
+ s+="number of sessions : "+str(len(cache_image))+"\n"
202
  for key, listT in cache_image.items():
203
+ s+="session "+key+" : "+str(len(listT))+"\n"
204
  lenTot+=len(listT)
205
+ s+="images total = "+str(lenTot)+"\n"
206
+ return s
 
207
 
208
  def disp_models(group_model_choice,nb_rep=nb_rep):
209
  listTemp=[]
 
320
  return nb_of_models_to_gen,gr.Textbox(str_temp),gr.Dropdown(choices=[["",list_models_temp]], value=list_models_temp )
321
 
322
  def crea_list_task(id_session,list_param,list_models_to_gen,nb_images_by_prompt):
323
+ if from_reload[f"{id_session}"]==True:
324
+ from_reload[f"{id_session}"]=False
325
+ return
326
  cache_list_task[f"{id_session}"]=[]
327
  dict_temp={}
328
  list_progress=[]
 
461
  i=0
462
  for model in list_models_to_gen:
463
  if model_actu==model:
464
+ 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"]))*7)//1)+2
465
  i+=1
466
  if len(model_plus_tasks["task"])==0:
467
  cache_list_task[f"{id_session}"].remove(model_plus_tasks)
 
544
  with gr.Tab(" Sort ",visible=False) as tab_p:
545
  button_test_pass.click(test_pass_aff,[test_pass],[tab_p])
546
  with gr.Column():
 
547
  with gr.Group():
548
  with gr.Row():
549
  with gr.Column(scale=4):
 
577
  inputs=[txt_input,neg_input,width,height,steps,cfg,seed],
578
  outputs=[txt_input,neg_input,width,height,steps,cfg,seed],
579
  )
580
+
581
+
582
+
583
+ with gr.Accordion("Restore Session",open=False) :
584
+ with gr.Row():
585
+ text_info_session=gr.Textbox()
586
+ with gr.Column():
587
+ button_info_session=gr.Button("Get infos sessions")
588
+ button_info_session.click(print_info_sessions,[],[text_info_session])
589
+ id_session=gr.Number(0,interactive = True,label="ID session",show_label=True)
590
+ button_restore_session=gr.Button("Restore Session")
591
+
592
+
593
+
594
  add_param.click(fonc_add_param,[list_param,txt_input,neg_input,width,height,steps,cfg,seed],[disp_param.dataset,list_param])
595
  add_param.click(set_session,[id_session],[id_session])
596
  del_param.click(fonc_del_param,[list_param,txt_input,neg_input,width,height,steps,cfg,seed],[disp_param.dataset,list_param])
597
+
598
  with gr.Row():
599
  list_models_to_gen=gr.Dropdown(choices=[["",[]]], value=[], visible=False)
600
  disp_info=gr.Textbox(label="Info")
 
624
 
625
  load_model_custom=gr.Button("Load Models Custom")
626
  load_model_custom.click(fonc_load_info_custom,[nb_of_models_to_gen,list_model_custom,index_first_model_custom],[nb_of_models_to_gen,disp_info,list_models_to_gen])
 
627
  list_models_to_gen.change(crea_list_task,[id_session,list_param,list_models_to_gen,nb_images_by_prompt],[])
628
 
629
 
 
757
 
758
 
759
 
760
+ button_restore_session.click(fonc_restore_session,[id_session],[list_param,disp_param.dataset,list_models_to_gen,nb_of_models_to_gen])
761
 
762
 
763
+
764
+
765
  js_code = """
766
 
767
  console.log('ghgh');