-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
87 lines (66 loc) · 2.84 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import argparse
import os
import shutil
import sys
import time
from fking.fking_captions import create_concept, print_concept_info
from fking.fking_utils import fix_prompt_text_files, generate_prompt_list, prompt_warning, write_tags
parser = argparse.ArgumentParser()
parser.add_argument("--no-ui", default=True, dest="use_ui", action='store_false')
parser.add_argument("-i", "--input", type=str)
parser.add_argument("-o", "--output", type=str, default=None)
parser.add_argument("--overwrite", default=False, dest="overwrite", action='store_true')
parser.add_argument("--preserve-underscores", default=False, dest="preserve_underscores", action='store_true')
parser.add_argument("--fix-prompts", default=False, dest="fix_prompts", action='store_true')
parser.add_argument("--no-tree", default=True, dest="tree", action="store_false")
args = parser.parse_args()
if args.use_ui:
import fking.captioner.fking_captioner
fking.captioner.fking_captioner.show_ui()
sys.exit()
input_directory = args.input
output_directory = args.output
merge_directory = os.path.join(output_directory, "merged_dataset") if output_directory is not None else None
if args.overwrite and os.path.exists(output_directory):
if prompt_warning(f"Output directory exists; are you sure you want to overwrite?\n '{output_directory}'"):
print()
print("Sanity check succeeded!")
print(f"Deleting output directory '{output_directory}', please wait...")
shutil.rmtree(output_directory)
pass
else:
print()
print("Exiting... Nothing was changed.")
exit()
if args.fix_prompts:
if prompt_warning(f"Are you sure you want to normalize prompt files in input folder?\n '{input_directory}'"
f"\n\nThis action is irreversible."):
print()
print("Sanity check succeeded!")
print(f"Fixing prompts... this may take a while...")
fix_prompt_text_files(input_directory)
pass
else:
print()
print("Exiting... Nothing was changed.")
exit()
print()
print("Generating output... please wait...")
print()
start_time_millis = time.time() * 1000.0
global_concept = create_concept("global", input_directory)
if args.tree:
print_concept_info(global_concept)
if output_directory is not None:
global_concept.write(merge_directory)
unique_prompts = generate_prompt_list(merge_directory)
unique_prompts_file_path = os.path.join(output_directory, "unique_prompt.txt")
with open(unique_prompts_file_path, "w+") as f:
f.writelines(up + "\n" for up in unique_prompts)
f.close()
unique_tags = sum([prompt.split(', ') for prompt in unique_prompts], [])
unique_tags_file_path = os.path.join(output_directory, "unique_tags.txt")
write_tags(unique_tags_file_path, unique_tags)
end_time_millis = time.time() * 1000.0
print("Done.")
print()