added comments to describe functions,'

This commit is contained in:
2024-02-13 23:25:12 -05:00
parent a1e753a6d0
commit 50576d2c37

View File

@@ -3,6 +3,7 @@ import os
from openai import OpenAI
from pytube import YouTube
# Downloads the audio from a YouTube video.
def download(video_url, output_filename='audio.mp4'):
try:
print("Downloading audio...")
@@ -15,6 +16,7 @@ def download(video_url, output_filename='audio.mp4'):
print(f"Failed to download audio: {e}")
return None
# Transcribes the audio file using OpenAI's transcription service.
def transcription(OPENAI_API_KEY, audio_filename):
try:
print("Transcriptiting audio...")
@@ -33,6 +35,7 @@ def transcription(OPENAI_API_KEY, audio_filename):
print(f"Failed to transcript audio: {e}")
return None
# Generates a summary for a given transcript using GPT-4.
def summary(OPENAI_API_KEY, transcript):
try:
print("Summarizing transcript...")
@@ -55,15 +58,17 @@ def summary(OPENAI_API_KEY, transcript):
print(f"Failed to summarize transcript: {e}")
return None
# Deletes the specified audio file.
def cleanup(audio_filename):
try:
print("Deleting audio...")
os.remove(audio_filename)
print(f"Deleted audio: {audio_filename}")
print(f"Deleted audio.")
except Exception as e:
print(f"Failed to delete audio: {e}")
return None
# Main function to orchestrate the download, transcription, summarization, and cleanup process.
def main():
try:
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')