-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
70 lines (56 loc) · 2.11 KB
/
gui.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
import os
# ANSI escape codes for different colors
class colors:
RED = '\033[91m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
BLUE = '\033[94m'
MAGENTA = '\033[95m'
CYAN = '\033[96m'
WHITE = '\033[97m'
RESET = '\033[0m'
# Example usage
# print(colors.RED + "This is red text" + colors.RESET)
def list_models_in_folder(folder_path):
# List all models in the given folder
models = [ file for file in os.listdir(folder_path) if file.endswith('.pth') ]
return models
def load_model(folder_path):
# Load the model specified by the user
models = list_models_in_folder(folder_path)
if not models:
print(colors.RED + "No models found in the folder." + colors.RESET)
return None # Not if it's the appropriate way to exit
print(colors.GREEN + "Models available in the folder:" + colors.RESET)
for i, model in enumerate(models, start=1):
print(colors.YELLOW + f"{i}. {model}" + colors.RESET)
print("")
while True:
choice = input("Enter the number of the model you want to load (or 'exit' to quit): ")
if choice.lower() == 'exit':
return None # Still unsure about this
try:
choice_idx = int(choice) - 1
if 0 <= choice_idx < len(models):
model_path = os.path.join(folder_path, models[choice_idx])
return model_path
else:
print(colors.RED + "Invalid choice. Please enter a valid number." + colors.RESET)
except ValueError:
print(colors.RED + "Invalid choice. Please enter a valid number." + colors.RESET)
'''
def main():
folder_path = input("Enter the folder path: ")
if not os.path.exists(folder_path):
print(colors.RED + "Folder doesn't exist." + colors.RESET)
return
if not os.listdir(folder_path):
print(colors.RED + "Folder is empty." + colors.RESET)
return
model_path = load_model(folder_path)
if model_path:
print(colors.BLUE + f"Loading model from {model_path}" + colors.RESET)
# Load the selected model
if __name__ == "__main__":
main()
'''