-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
79 lines (59 loc) · 2.46 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
# import wisper
import call_GPT_cascade
import argparse
import os
import constants
import wisper
from pathlib import Path
def create_dir_if_not_exists(dir_path):
"""Create a directory if it does not exist."""
if not os.path.exists(dir_path):
os.makedirs(dir_path)
def get_args():
"""Get the arguments from the command line."""
parser = argparse.ArgumentParser(description="Process a filename.")
parser.add_argument(
"--input_dir_or_file", type=str, help="The name of the file to process"
)
parser.add_argument(
"--final_output_dir",
type=str,
help="The name of the file to process",
default="./data/output/",
)
return parser.parse_args()
def apply_pipeline_to_file(file_path, final_output_dir):
"""Apply the pipeline to a file."""
# if the file_path contains spaces, move it to a new file without spaces
if " " in file_path:
new_file_path = file_path.replace(" ", "_")
os.rename(file_path, new_file_path)
file_path = new_file_path
extension = file_path.split(".")[-1].lower()
if extension in constants.supported_extensions:
wisper.mainTranscribe(file_path)
call_GPT_cascade.main(
filename=file_path.split("/")[-1].split(".")[0],
final_output_dir=final_output_dir,
)
if __name__ == "__main__":
args = get_args()
create_dir_if_not_exists(args.final_output_dir)
if os.path.isfile(args.input_dir_or_file):
apply_pipeline_to_file(args.input_dir_or_file, args.final_output_dir)
if os.path.isdir(args.input_dir_or_file):
for fichier in Path(args.input_dir_or_file).rglob('*'):
if fichier.is_file():
print(f"Processing file: {fichier} in {args.input_dir_or_file}")
# Calculer le chemin relatif du sous-dossier contenant le fichier
sous_dossier = fichier.parent.relative_to(args.input_dir_or_file)
print(f"Fichier: {fichier}, Sous-dossier: {sous_dossier}")
final_output_dir = os.path.join(args.final_output_dir, sous_dossier)
create_dir_if_not_exists(final_output_dir)
apply_pipeline_to_file(
fichier._str, final_output_dir
)
# for file in os.listdir(args.input_dir_or_file):
# apply_pipeline_to_file(
# os.path.join(args.input_dir_or_file, file), args.final_output_dir
# )