yfszzx / stable-diffusion-webui-images-browser

an images browse for stable-diffusion-webui
486 stars 234 forks source link

Mass Delete #37

Open MoezFalomen opened 1 year ago

MoezFalomen commented 1 year ago

Feature request:

It would be good to select multiple images to delete. This can be done by selecting the images from the Web GUI or specifying indices (i.e. 1,2,3 or 1-10,32,45). This will be particularly useful for Colab notebooks.

Ju1-js commented 1 year ago

@yfszzx The text parsing part of this feature could be done with something like this:

import re

input = "1---3.0dde, 5, 7,9, 15-20, 2" # Messing with spaces, too many dashes, duplicate numbers and decimals to stress test the code
out = ""
for ii in re.sub('[^0123456789,-.]', '', input).replace(" ", "").split(","):
    out += re.sub('[^0123456789,-]', '', re.sub('--+', '-', re.sub('\\.\\d+$', '', ii))) + ","
input = out[:-1].split(",")
numbers = []
for i in input:
    if "-" in i:
        start, end = i.split("-")
        numbers += range(int(start), int(end) + 1)
    else:
        numbers.append(int(i))
numbers.sort() # So the list looks nice, not necessary
numbers = list(set(numbers)) # Remove duplicates
print(numbers)

You would also need to change your gr.Number input to a gr.Textbox. Then the array should be sent to a slightly modified version of your delete function.