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 openai import OpenAI
|
||||||
from pytube import YouTube
|
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.
|
# Downloads the audio from a YouTube video.
|
||||||
def download(video_url, output_filename='audio.mp4'):
|
def download(video_url, output_filename='audio.mp4'):
|
||||||
try:
|
try:
|
||||||
@@ -71,14 +79,18 @@ def cleanup(audio_filename):
|
|||||||
# Main function to orchestrate the download, transcription, summarization, and cleanup process.
|
# Main function to orchestrate the download, transcription, summarization, and cleanup process.
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
|
OPENAI_API_KEY = get_api_key()
|
||||||
video_url = str(input("video url:"))
|
video_url = str(input("Video url: "))
|
||||||
audio_filename = download(video_url)
|
audio_filename = download(video_url)
|
||||||
|
if audio_filename is not None:
|
||||||
transcript = transcription(OPENAI_API_KEY, audio_filename)
|
transcript = transcription(OPENAI_API_KEY, audio_filename)
|
||||||
|
if transcript is not None:
|
||||||
summary(OPENAI_API_KEY, transcript)
|
summary(OPENAI_API_KEY, transcript)
|
||||||
cleanup(audio_filename)
|
cleanup(audio_filename)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
finally:
|
||||||
|
input("Press Enter to exit...")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user