P01yH3dr0n commited on
Commit
878850d
1 Parent(s): 8b4dd05

Update images_history.py

Browse files
Files changed (1) hide show
  1. images_history.py +17 -0
images_history.py CHANGED
@@ -28,6 +28,20 @@ def get_img_info(evt: gr.SelectData):
28
  index = evt.index
29
  return index, info, items
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  def img_history_ui(tab):
32
  os.makedirs(client_config['save_path'], exist_ok=True)
33
  all_dirs = os.listdir(client_config['save_path'])
@@ -51,6 +65,7 @@ def img_history_ui(tab):
51
  selected_index = gr.Number(value=-1, visible=False, precision=0)
52
  with gr.Row():
53
  send_btn = gr.Button('参数发送到文生图')
 
54
 
55
  img_dir_path.change(lambda path: get_img_list(path, 1) + ('', None), inputs=img_dir_path, outputs=[history_gallery, page_index, info, items])
56
  img_dir_path.blur(update_img_dir, inputs=None, outputs=img_dir_path)
@@ -60,5 +75,7 @@ def img_history_ui(tab):
60
  next_page.click(lambda path, p: get_img_list(path, p + 1) + ('', None), inputs=[img_dir_path, page_index], outputs=[history_gallery, page_index, info, items])
61
  end_page.click(lambda path: get_img_list(path, -1) + ('', None), inputs=img_dir_path, outputs=[history_gallery, page_index, info, items])
62
  history_gallery.select(get_img_info, inputs=None, outputs=[selected_index, info, items])
 
 
63
 
64
  return send_btn, items
 
28
  index = evt.index
29
  return index, info, items
30
 
31
+ def del_img(index, folder, page):
32
+ if index < 0:
33
+ return gr.Gallery(selected_index=None)
34
+ img_list = [os.path.join(client_config['save_path'], folder, f) for f in os.listdir(os.path.join(client_config['save_path'], folder))]
35
+ img_list.sort(key=lambda f: os.path.getctime(f), reverse=True)
36
+ if page == 0:
37
+ page = 1
38
+ elif page*num_of_imgs_per_page > len(img_list) or page < 0:
39
+ page = ceil(len(img_list)/num_of_imgs_per_page)
40
+ res = img_list[(page - 1)*num_of_imgs_per_page: page*num_of_imgs_per_page]
41
+ os.remove(res[index])
42
+ res.pop(index)
43
+ return gr.Gallery(value=res, selected_index=None)
44
+
45
  def img_history_ui(tab):
46
  os.makedirs(client_config['save_path'], exist_ok=True)
47
  all_dirs = os.listdir(client_config['save_path'])
 
65
  selected_index = gr.Number(value=-1, visible=False, precision=0)
66
  with gr.Row():
67
  send_btn = gr.Button('参数发送到文生图')
68
+ del_btn = gr.Button('Delete')
69
 
70
  img_dir_path.change(lambda path: get_img_list(path, 1) + ('', None), inputs=img_dir_path, outputs=[history_gallery, page_index, info, items])
71
  img_dir_path.blur(update_img_dir, inputs=None, outputs=img_dir_path)
 
75
  next_page.click(lambda path, p: get_img_list(path, p + 1) + ('', None), inputs=[img_dir_path, page_index], outputs=[history_gallery, page_index, info, items])
76
  end_page.click(lambda path: get_img_list(path, -1) + ('', None), inputs=img_dir_path, outputs=[history_gallery, page_index, info, items])
77
  history_gallery.select(get_img_info, inputs=None, outputs=[selected_index, info, items])
78
+ history_gallery.change(lambda: -1, outputs=selected_index)
79
+ del_btn.click(del_img, inputs=[selected_index, img_dir_path, page_index], outputs=history_gallery)
80
 
81
  return send_btn, items