-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (69 loc) · 2.15 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
# main.py
import os
import sys
import argparse
from dotenv import load_dotenv
from app import __version__
from utils.__env import *
from utils.conf import load_config
from utils.file import create_output_directory, get_supported_files
from utils.preprocess import preprocess_media
"""
Parse command-line arguments
"""
def create_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="PreProcessing")
parser.add_argument(
"-t",
"--type",
type=str,
default="image",
choices=["image", "i", "video", "v"],
help="Specify the data type: 'image(i)' or 'video(v)' (default: 'image')"
)
parser.add_argument(
"-p",
"--path",
type=str,
default="./assets",
help="Path to images or video files (default: './assets')"
)
parser.add_argument(
"-c",
"--config",
default="./config.yaml",
type=str,
help="Path to the configuration file (default: './config.yaml')"
)
parser.add_argument(
"-o",
"--output",
default="./result",
type=str,
help="Path to the output directory (default: './result')"
)
return parser
"""
Main function
"""
def main(args: argparse.Namespace) -> None:
# App information
print(f"==================================")
print(f"App version: {__version__}")
print(f"Python version: {sys.version}")
print(f"==================================")
# Load configuration and setup output directory
config_data = load_config(args.config)
output_directory = args.output
create_output_directory(output_directory)
data_type = args.type
input_path = args.path
# Get supported files for preprocessing
supported_files = get_supported_files(input_path, data_type)
# Preprocess the files
if supported_files:
media_settings = config_data.get("image_settings", {}) if data_type in ["image", "i"] else config_data.get("video_settings", {})
preprocess_media(supported_files, output_directory, media_settings)
if __name__ == "__main__":
command_args = create_parser().parse_args()
main(command_args)