-
Notifications
You must be signed in to change notification settings - Fork 51
/
app.py
90 lines (73 loc) · 2.75 KB
/
app.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
# Standard library imports
import os
import warnings
import logging
# Third party imports
from dotenv import load_dotenv
import lockfile
# Local application imports
import clipper
import extracts
import subtitler
import transcribe
from ytdl import main as ytdl_main
from local_whisper import local_whisper_process
# Setup logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
warnings.filterwarnings("ignore")
# Load environment variables
load_dotenv()
# List of required environment variables
required_vars = ['OPENAI_API_KEY', 'GEMINI_API_KEY']
"""
This for loop checks if the required environment variables are set.
If any of the required environment variables are set to 'None', an EnvironmentError is raised.
"""
for var in required_vars:
value = os.getenv(var)
if value is None or value == 'None':
raise EnvironmentError(f"Required environment variable {var} is not set or is set to 'None'.")
def main():
input_folder = './input_files'
output_video_folder = './clipper_output'
crew_output_folder = './crew_output'
whisper_output_folder = './whisper_output'
# User selection
def user_prompt():
"""Prompt the user to select an option to proceed"""
logging.info("Please select an option to proceed:")
logging.info("1: Submit a YouTube Video Link")
logging.info("2: Use an existing video file")
def user_choice():
"""Get the user's choice"""
choice = input("Please choose either option 1 or 2: ")
return choice
while True:
user_prompt() # Display the prompt before asking for the choice
choice = user_choice()
if choice == '1':
logging.info("Submitting a YouTube Video Link")
# Download video from YouTube
url = input("Enter the YouTube URL: ")
ytdl_main(url, input_folder, whisper_output_folder, whisper_output_folder)
transcribe_flag = False
break
elif choice == '2':
logging.info("Using an existing video file")
if not os.listdir(input_folder):
logging.error(f"No video files found in the folder: {input_folder}")
continue
transcribe_flag = True
break
else:
logging.info("Invalid choice. Please try again.")
try:
os.makedirs(output_video_folder, exist_ok=True)
os.makedirs(crew_output_folder, exist_ok=True)
os.makedirs(whisper_output_folder, exist_ok=True)
except Exception as e:
logging.error(f"Error creating directories: {e}")
return
local_whisper_process(input_folder, output_video_folder, crew_output_folder, transcribe_flag=transcribe_flag)
if __name__ == "__main__":
main()