-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser_input.py
106 lines (97 loc) · 3.94 KB
/
user_input.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import time
import variable
from tqdm import tqdm
def select_option():
output_upperbody_folder = variable.output_upperbody_folder
debug_upperbody_folder = variable.debug_upperbody_folder
output_face_folder = variable.output_face_folder
debug_face_folder = variable.debug_face_folder
output_fullbody_folder = variable.output_fullbody_folder
debug_fullbody_folder = variable.debug_fullbody_folder
while True:
option = input("Select a crop type:\n1. Upper Body\n2. Face\n3. Full body (try to crop as much as possible)\nSelect: ")
if option not in ["1", "2", "3"]:
print("Invalid option selected. Please try again.")
print("")
else:
break
if option == "1":
top_margin_value = 1
bottom_margin_value = 3
debug_output = debug_upperbody_folder
output_folder = output_upperbody_folder
croptype = 1
elif option == "2":
top_margin_value = 0.25
bottom_margin_value = 0.25
debug_output = debug_face_folder
output_folder = output_face_folder
croptype = 2
elif option == "3":
top_margin_value = 1
bottom_margin_value = 12
debug_output = debug_fullbody_folder
output_folder = output_fullbody_folder
croptype = 3
return [top_margin_value, #type: ignore
bottom_margin_value, #type: ignore
debug_output, #type: ignore
output_folder, #type: ignore
croptype] #type: ignore
def preview_window():
show_preview = False
multithread = False
while True:
show_preview = input("Show preview window? [Y]es/[N]o: ")
if show_preview.lower() == "y":
show_preview = True
parallel = False
break
elif show_preview.lower() == "n":
show_preview = False
parallel = True
break
else:
print("Invalid option selected. Please enter 'Y' or 'N'.")
print("")
return show_preview, parallel
def clean_output(output_folder, debug_output, error_folder):
while len(os.listdir(output_folder)) > 0:
file_exist = input("Output folders are not empty, clean it? [Y]es/[N]o: ")
if file_exist.lower() == "y":
i = 5
while i <= 5 and i > 0:
# Add a delay of 5 seconds before proceeding with the deletion
print(f"\rDeleting files in {i}... [PRESS CTRL+C TO CANCEL]")
time.sleep(1)
i -= 1
# Get the total number of files
total_files = sum([len(files) for _, _, files in os.walk(output_folder)])
# Deleting files in the output folder and subdirectories with a progress bar
with tqdm(total=total_files, unit='file') as pbar:
for root, dirs, files in os.walk(output_folder):
for file_name in files:
file_path = os.path.join(root, file_name)
os.remove(file_path)
pbar.update(1)
with tqdm(total=total_files, unit='file') as pbar:
for root, dirs, files in os.walk(debug_output):
for file_name in files:
file_path = os.path.join(root, file_name)
os.remove(file_path)
pbar.update(1)
with tqdm(total=total_files, unit='file') as pbar:
for root, dirs, files in os.walk(error_folder):
for file_name in files:
file_path = os.path.join(root, file_name)
os.remove(file_path)
pbar.update(1)
print("Done cleaning the output folder.")
print("")
elif file_exist.lower() == "n":
print("")
break # Exit the while loop
else:
print("Invalid option selected. Please enter 'Y' or 'N'.")
print("")