added comments to describe functions,'
This commit is contained in:
7
main.py
7
main.py
@@ -3,6 +3,7 @@ import os
|
|||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
from pytube import YouTube
|
from pytube import YouTube
|
||||||
|
|
||||||
|
# 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:
|
||||||
print("Downloading audio...")
|
print("Downloading audio...")
|
||||||
@@ -15,6 +16,7 @@ def download(video_url, output_filename='audio.mp4'):
|
|||||||
print(f"Failed to download audio: {e}")
|
print(f"Failed to download audio: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# Transcribes the audio file using OpenAI's transcription service.
|
||||||
def transcription(OPENAI_API_KEY, audio_filename):
|
def transcription(OPENAI_API_KEY, audio_filename):
|
||||||
try:
|
try:
|
||||||
print("Transcriptiting audio...")
|
print("Transcriptiting audio...")
|
||||||
@@ -33,6 +35,7 @@ def transcription(OPENAI_API_KEY, audio_filename):
|
|||||||
print(f"Failed to transcript audio: {e}")
|
print(f"Failed to transcript audio: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# Generates a summary for a given transcript using GPT-4.
|
||||||
def summary(OPENAI_API_KEY, transcript):
|
def summary(OPENAI_API_KEY, transcript):
|
||||||
try:
|
try:
|
||||||
print("Summarizing transcript...")
|
print("Summarizing transcript...")
|
||||||
@@ -55,15 +58,17 @@ def summary(OPENAI_API_KEY, transcript):
|
|||||||
print(f"Failed to summarize transcript: {e}")
|
print(f"Failed to summarize transcript: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# Deletes the specified audio file.
|
||||||
def cleanup(audio_filename):
|
def cleanup(audio_filename):
|
||||||
try:
|
try:
|
||||||
print("Deleting audio...")
|
print("Deleting audio...")
|
||||||
os.remove(audio_filename)
|
os.remove(audio_filename)
|
||||||
print(f"Deleted audio: {audio_filename}")
|
print(f"Deleted audio.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to delete audio: {e}")
|
print(f"Failed to delete audio: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# 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 = os.environ.get('OPENAI_API_KEY')
|
||||||
|
|||||||
Reference in New Issue
Block a user