DemiPoto commited on
Commit
dedc0a4
·
verified ·
1 Parent(s): 14bd628

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -19
app.py CHANGED
@@ -90,7 +90,7 @@ async def infer(model_str, prompt, nprompt="", height=None, width=None, steps=No
90
  noise += " "
91
  task = asyncio.create_task(asyncio.to_thread(models_load[model_str].fn,
92
  prompt=f'{prompt} {noise}', negative_prompt=nprompt, **kwargs, token=HF_TOKEN))
93
- await asyncio.sleep(0)
94
  try:
95
  result = await asyncio.wait_for(task, timeout=timeout)
96
  except (Exception, asyncio.TimeoutError) as e:
@@ -337,9 +337,14 @@ def reset_gallery(gallery):
337
  return add_gallery(None,"",[])
338
  def fonc_load_gallery(id_session,gallery):
339
  gallery = reset_gallery(gallery)
340
- print(cache_image[f"{id_session}"])
341
  for i in range(len(cache_image[f"{id_session}"])):
342
- gallery=add_gallery(cache_image[f"{id_session}"][i],cache_id_image[f"{id_session}"][i]["model"],gallery)
 
 
 
 
 
 
343
  return gallery
344
 
345
  def fonc_start(id_session,id_module,s,cont):
@@ -383,9 +388,10 @@ def fonc_start(id_session,id_module,s,cont):
383
 
384
  task_actu["id_image"]=id_image
385
  task_actu["model"]=model_actu
386
- #cache_image[f"{id_session}"].append(result.value)
387
- cache_image[f"{id_session}"].append(result)
388
- cache_id_image[f"{id_session}"].append(task_actu)
 
389
  print("image saved\n")
390
  else:
391
  print("fail to generate\n")
@@ -396,17 +402,18 @@ def fonc_start(id_session,id_module,s,cont):
396
  print(f"\n {num_task_undo} tasks undo\n")
397
  return result , gr.Textbox(s+"1")
398
 
399
- def test_change(s):
400
- if s == "11111":
401
- return gr.Textbox(s)
402
- else:
403
- print(s)
404
- return gr.Textbox(s+"1")
405
- #return None
406
- def test_start(s):
407
- print("go\n")
408
  return gr.Textbox(s+"1")
409
 
 
 
 
 
 
 
 
 
 
410
  def make_me():
411
  with gr.Column():
412
  id_session=gr.Number(visible=False,value=0)
@@ -508,15 +515,26 @@ def make_me():
508
  #o.change(test_change,[],[])
509
  s.change(fonc_start,[id_session,i,s,cont],[o,s])
510
  #button_start.click(lambda : gr.Image(None),[],[o])
511
- gen_event = gr.on(triggers=[button_start.click], fn=test_start,inputs=[s], outputs=[s])
512
 
513
  gallery = gr.Gallery(label="Output", show_download_button=True, elem_classes="gallery",
514
  interactive=False, show_share_button=True, container=True, format="png",
515
  preview=True, object_fit="cover",columns=4,rows=4)
516
- button_load_gallery=gr.Button("Load Gallery")
517
- button_load_gallery.click(fonc_load_gallery,[id_session,gallery],[gallery])
518
-
519
 
 
 
 
 
 
 
 
 
 
 
 
520
 
521
 
522
 
 
90
  noise += " "
91
  task = asyncio.create_task(asyncio.to_thread(models_load[model_str].fn,
92
  prompt=f'{prompt} {noise}', negative_prompt=nprompt, **kwargs, token=HF_TOKEN))
93
+ await asyncio.sleep(3)
94
  try:
95
  result = await asyncio.wait_for(task, timeout=timeout)
96
  except (Exception, asyncio.TimeoutError) as e:
 
337
  return add_gallery(None,"",[])
338
  def fonc_load_gallery(id_session,gallery):
339
  gallery = reset_gallery(gallery)
 
340
  for i in range(len(cache_image[f"{id_session}"])):
341
+ gallery=add_gallery(cache_image[f"{id_session}"][i]["image"],cache_image[f"{id_session}"][i]["model"],gallery)
342
+ return gallery
343
+ def fonc_load_gallery_by_model(id_session,gallery,models,index):
344
+ gallery = reset_gallery(gallery)
345
+ for i in range(len(cache_image[f"{id_session}"])):
346
+ if cache_image[f"{id_session}"][i]["model"]==models[index]:
347
+ gallery=add_gallery(cache_image[f"{id_session}"][i]["image"],cache_image[f"{id_session}"][i]["model"],gallery)
348
  return gallery
349
 
350
  def fonc_start(id_session,id_module,s,cont):
 
388
 
389
  task_actu["id_image"]=id_image
390
  task_actu["model"]=model_actu
391
+ task_actu["image"]=result
392
+ #cache_image[f"{id_session}"].append(result)
393
+ #cache_id_image[f"{id_session}"].append(task_actu)
394
+ cache_image[f"{id_session}"].append(task_actu)
395
  print("image saved\n")
396
  else:
397
  print("fail to generate\n")
 
402
  print(f"\n {num_task_undo} tasks undo\n")
403
  return result , gr.Textbox(s+"1")
404
 
405
+ def fonc_init(s):
 
 
 
 
 
 
 
 
406
  return gr.Textbox(s+"1")
407
 
408
+ def index_gallery_first():
409
+ return gr.Number(0)
410
+ def index_gallery_next(i,list_models):
411
+ iT=i+1
412
+ return gr.Number(iT%len(list_models))
413
+ def index_gallery_prev(i,list_models):
414
+ iT=i-1
415
+ return gr.Number(iT%len(list_models))
416
+
417
  def make_me():
418
  with gr.Column():
419
  id_session=gr.Number(visible=False,value=0)
 
515
  #o.change(test_change,[],[])
516
  s.change(fonc_start,[id_session,i,s,cont],[o,s])
517
  #button_start.click(lambda : gr.Image(None),[],[o])
518
+ gen_event = gr.on(triggers=[button_start.click], fn=fonc_init,inputs=[s], outputs=[s])
519
 
520
  gallery = gr.Gallery(label="Output", show_download_button=True, elem_classes="gallery",
521
  interactive=False, show_share_button=True, container=True, format="png",
522
  preview=True, object_fit="cover",columns=4,rows=4)
523
+ with gr.Column():
524
+ button_load_gallery=gr.Button("Load Gallery All")
525
+ button_load_gallery.click(fonc_load_gallery,[id_session,gallery],[gallery])
526
 
527
+ index_gallery=gr.Number(0,visible=False)
528
+ button_load_gallery_first=gr.Button("Load Gallery first model")
529
+ button_load_gallery_first.click(index_gallery_first,[],[index_gallery])
530
+ with gr.Row():
531
+ button_load_gallery_next=gr.Button("Next model")
532
+ button_load_gallery_next.click(index_gallery_next,[index_gallery,list_models_to_gen],[index_gallery])
533
+ button_load_gallery_prev=gr.Button("Prev model")
534
+ button_load_gallery_prev.click(index_gallery_prev,[index_gallery,list_models_to_gen],[index_gallery])
535
+ index_gallery.change(fonc_load_gallery_by_model,[id_session,gallery,list_models_to_gen,index_gallery],[gallery])
536
+
537
+
538
 
539
 
540