Upload 2 files
Browse filesFiles changed (3)
100 unmodified lines101102103100 unmodified linesDanbooru[[:space:]]Prompt[[:space:]]Selector/prompt_selector_1215.exe filter=lfs diff=lfs merge=lfs -textDanbooru[[:space:]]Prompt[[:space:]]Selector/prompt_selector_auto_1215.exe filter=lfs diff=lfs merge=lfs -textDanbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/prompt_selector_auto_1215_testv9.exe filter=lfs diff=lfs merge=lfs -text100 unmodified lines101102103104100 unmodified linesDanbooru[[:space:]]Prompt[[:space:]]Selector/prompt_selector_1215.exe filter=lfs diff=lfs merge=lfs -textDanbooru[[:space:]]Prompt[[:space:]]Selector/prompt_selector_auto_1215.exe filter=lfs diff=lfs merge=lfs -textDanbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/prompt_selector_auto_1215_testv9.exe filter=lfs diff=lfs merge=lfs -textDanbooru[[:space:]]Prompt[[:space:]]Selector/autosort/NAI_generated_image_autosort.exe filter=lfs diff=lfs merge=lfs -text
123version https://git-lfs.github.com/spec/v1oid sha256:6ce56ca613c0c3f797af9eec3e6077dd44d72a619d49d4fb5fc0b62606f305d1size 3086539012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970import osimport reimport shutilfrom tkinter import Tk, Text, Button, Label, filedialog, messagebox, scrolledtextfrom PIL import Image
def extract_keywords(filename): with Image.open(filename) as img: return img.info.get('Description', '')
def sort_files(): folder_path = os.getcwd() if not folder_path: return
files = [f for f in os.listdir(folder_path) if f.endswith('.png')]
# Read wildcard_artists from the text widget wildcard_artist_lines = text_widget.get("1.0", "end-1c").split('\n') wildcard_artist = { line: re.sub(r'[{[\]}]', '', line).replace('artist:', '').replace(':', '').replace(', ', '_').replace(',', '_').strip() for line in wildcard_artist_lines if line.strip() } file_count_per_artist = {value: 0 for value in wildcard_artist.values()}
# Sort the files based on the wildcard_artists for i, file in enumerate(files): curr_keywords = extract_keywords(os.path.join(folder_path, file)) moved = False for key, value in wildcard_artist.items(): if key in curr_keywords: # Move the file to the new folder sorted_folder = os.path.join(folder_path, f'sorted/{value}') os.makedirs(sorted_folder, exist_ok=True) shutil.move(os.path.join(folder_path, file), sorted_folder) file_count_per_artist[value] += 1 moved = True break if not moved: # If the file does not match any artist, increment the count for 'unsorted' file_count_per_artist.setdefault('unsorted', 0) file_count_per_artist['unsorted'] += 1 # Write results to file with open(os.path.join(folder_path, 'result.txt'), 'w') as result_file: for artist, count in file_count_per_artist.items(): result_file.write(f"{artist}: {count} files moved\n")
# Show message box with the result messagebox.showinfo("Sorting Complete", f"Files have been sorted. Check result.txt for details.")
# Create the main windowroot = Tk()root.title('Image Sorter')
# Create a text widget for wildcard_artiststext_widget = scrolledtext.ScrolledText(root, height=10)text_widget.pack()
# Create a labellabel = Label(root, text="Enter wildcard artists, one per line:")label.pack()
# Create a button to trigger the sortingsort_button = Button(root, text="Sort Files", command=sort_files)sort_button.pack()
# Run the main looproot.mainloop().gitattributes+1
Danbooru Prompt Selector/autosort/NAI_generated_image_autosort.exeAdded+3
Danbooru Prompt Selector/autosort/NAI_generated_image_autosort.pyAdded+70