added some spaces for visibility.
This commit is contained in:
8
main.py
8
main.py
@@ -7,7 +7,9 @@ from pytube import YouTube
|
||||
def get_api_key():
|
||||
try:
|
||||
print("Retreiving OpenAI API Key...")
|
||||
|
||||
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
|
||||
|
||||
print(f"Retreived OpenAI API Key.")
|
||||
return OPENAI_API_KEY
|
||||
except Exception as e:
|
||||
@@ -18,9 +20,11 @@ def get_api_key():
|
||||
def download(video_url, output_filename='audio.mp4'):
|
||||
try:
|
||||
print("Downloading audio...")
|
||||
|
||||
yt = YouTube(video_url)
|
||||
audio_stream = yt.streams.get_audio_only()
|
||||
audio_filename = audio_stream.download(filename=output_filename)
|
||||
|
||||
print(f"Downloaded audio.")
|
||||
return audio_filename
|
||||
except Exception as e:
|
||||
@@ -49,6 +53,7 @@ def transcription(OPENAI_API_KEY, audio_filename):
|
||||
def summary(OPENAI_API_KEY, transcript):
|
||||
try:
|
||||
print("Summarizing transcript...")
|
||||
|
||||
client = OpenAI(api_key=OPENAI_API_KEY)
|
||||
stream = client.chat.completions.create(
|
||||
model="gpt-4",
|
||||
@@ -72,7 +77,9 @@ def summary(OPENAI_API_KEY, transcript):
|
||||
def cleanup(audio_filename):
|
||||
try:
|
||||
print("Deleting audio...")
|
||||
|
||||
os.remove(audio_filename)
|
||||
|
||||
print(f"Deleted audio.")
|
||||
except Exception as e:
|
||||
print(f"Failed to delete audio: {e}")
|
||||
@@ -83,6 +90,7 @@ def main():
|
||||
try:
|
||||
OPENAI_API_KEY = get_api_key()
|
||||
video_url = str(input("Video url: "))
|
||||
|
||||
if OPENAI_API_KEY is not None:
|
||||
audio_filename = download(video_url)
|
||||
if audio_filename is not None:
|
||||
|
||||
Reference in New Issue
Block a user