Upload 2 files
Browse files
.gitattributes
CHANGED
@@ -101,3 +101,4 @@ Danbooru[[:space:]]Prompt[[:space:]]Selector/.py_version/tags.csv filter=lfs dif
|
|
101 |
Danbooru[[:space:]]Prompt[[:space:]]Selector/prompt_selector_1215.exe filter=lfs diff=lfs merge=lfs -text
|
102 |
Danbooru[[:space:]]Prompt[[:space:]]Selector/prompt_selector_auto_1215.exe filter=lfs diff=lfs merge=lfs -text
|
103 |
Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/prompt_selector_auto_1215_testv9.exe filter=lfs diff=lfs merge=lfs -text
|
|
|
|
101 |
Danbooru[[:space:]]Prompt[[:space:]]Selector/prompt_selector_1215.exe filter=lfs diff=lfs merge=lfs -text
|
102 |
Danbooru[[:space:]]Prompt[[:space:]]Selector/prompt_selector_auto_1215.exe filter=lfs diff=lfs merge=lfs -text
|
103 |
Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/prompt_selector_auto_1215_testv9.exe filter=lfs diff=lfs merge=lfs -text
|
104 |
+
Danbooru[[:space:]]Prompt[[:space:]]Selector/autosort/NAI_generated_image_autosort.exe filter=lfs diff=lfs merge=lfs -text
|
Danbooru Prompt Selector/autosort/NAI_generated_image_autosort.exe
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6ce56ca613c0c3f797af9eec3e6077dd44d72a619d49d4fb5fc0b62606f305d1
|
3 |
+
size 30865390
|
Danbooru Prompt Selector/autosort/NAI_generated_image_autosort.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import re
|
3 |
+
import shutil
|
4 |
+
from tkinter import Tk, Text, Button, Label, filedialog, messagebox, scrolledtext
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
def extract_keywords(filename):
|
8 |
+
with Image.open(filename) as img:
|
9 |
+
return img.info.get('Description', '')
|
10 |
+
|
11 |
+
def sort_files():
|
12 |
+
folder_path = os.getcwd()
|
13 |
+
if not folder_path:
|
14 |
+
return
|
15 |
+
|
16 |
+
files = [f for f in os.listdir(folder_path) if f.endswith('.png')]
|
17 |
+
|
18 |
+
# Read wildcard_artists from the text widget
|
19 |
+
wildcard_artist_lines = text_widget.get("1.0", "end-1c").split('\n')
|
20 |
+
wildcard_artist = {
|
21 |
+
line: re.sub(r'[{[\]}]', '', line).replace('artist:', '').replace(':', '').replace(', ', '_').replace(',', '_').strip()
|
22 |
+
for line in wildcard_artist_lines if line.strip()
|
23 |
+
}
|
24 |
+
|
25 |
+
file_count_per_artist = {value: 0 for value in wildcard_artist.values()}
|
26 |
+
|
27 |
+
# Sort the files based on the wildcard_artists
|
28 |
+
for i, file in enumerate(files):
|
29 |
+
curr_keywords = extract_keywords(os.path.join(folder_path, file))
|
30 |
+
moved = False
|
31 |
+
for key, value in wildcard_artist.items():
|
32 |
+
if key in curr_keywords:
|
33 |
+
# Move the file to the new folder
|
34 |
+
sorted_folder = os.path.join(folder_path, f'sorted/{value}')
|
35 |
+
os.makedirs(sorted_folder, exist_ok=True)
|
36 |
+
shutil.move(os.path.join(folder_path, file), sorted_folder)
|
37 |
+
file_count_per_artist[value] += 1
|
38 |
+
moved = True
|
39 |
+
break
|
40 |
+
if not moved:
|
41 |
+
# If the file does not match any artist, increment the count for 'unsorted'
|
42 |
+
file_count_per_artist.setdefault('unsorted', 0)
|
43 |
+
file_count_per_artist['unsorted'] += 1
|
44 |
+
|
45 |
+
# Write results to file
|
46 |
+
with open(os.path.join(folder_path, 'result.txt'), 'w') as result_file:
|
47 |
+
for artist, count in file_count_per_artist.items():
|
48 |
+
result_file.write(f"{artist}: {count} files moved\n")
|
49 |
+
|
50 |
+
# Show message box with the result
|
51 |
+
messagebox.showinfo("Sorting Complete", f"Files have been sorted. Check result.txt for details.")
|
52 |
+
|
53 |
+
# Create the main window
|
54 |
+
root = Tk()
|
55 |
+
root.title('Image Sorter')
|
56 |
+
|
57 |
+
# Create a text widget for wildcard_artists
|
58 |
+
text_widget = scrolledtext.ScrolledText(root, height=10)
|
59 |
+
text_widget.pack()
|
60 |
+
|
61 |
+
# Create a label
|
62 |
+
label = Label(root, text="Enter wildcard artists, one per line:")
|
63 |
+
label.pack()
|
64 |
+
|
65 |
+
# Create a button to trigger the sorting
|
66 |
+
sort_button = Button(root, text="Sort Files", command=sort_files)
|
67 |
+
sort_button.pack()
|
68 |
+
|
69 |
+
# Run the main loop
|
70 |
+
root.mainloop()
|