added error handling for api key missing
This commit is contained in:
16
main.py
16
main.py
@@ -3,6 +3,14 @@ import os
|
||||
from openai import OpenAI
|
||||
from pytube import YouTube
|
||||
|
||||
def get_api_key():
|
||||
try:
|
||||
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
|
||||
return OPENAI_API_KEY
|
||||
except Exception as e:
|
||||
print(f"Failed to retrieve OpenAI API Key: {e}")
|
||||
return None
|
||||
|
||||
# Downloads the audio from a YouTube video.
|
||||
def download(video_url, output_filename='audio.mp4'):
|
||||
try:
|
||||
@@ -71,14 +79,18 @@ def cleanup(audio_filename):
|
||||
# Main function to orchestrate the download, transcription, summarization, and cleanup process.
|
||||
def main():
|
||||
try:
|
||||
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
|
||||
video_url = str(input("video url:"))
|
||||
OPENAI_API_KEY = get_api_key()
|
||||
video_url = str(input("Video url: "))
|
||||
audio_filename = download(video_url)
|
||||
if audio_filename is not None:
|
||||
transcript = transcription(OPENAI_API_KEY, audio_filename)
|
||||
if transcript is not None:
|
||||
summary(OPENAI_API_KEY, transcript)
|
||||
cleanup(audio_filename)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
finally:
|
||||
input("Press Enter to exit...")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user