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():
|
def get_api_key():
|
||||||
try:
|
try:
|
||||||
print("Retreiving OpenAI API Key...")
|
print("Retreiving OpenAI API Key...")
|
||||||
|
|
||||||
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
|
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
|
||||||
|
|
||||||
print(f"Retreived OpenAI API Key.")
|
print(f"Retreived OpenAI API Key.")
|
||||||
return OPENAI_API_KEY
|
return OPENAI_API_KEY
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -18,9 +20,11 @@ def get_api_key():
|
|||||||
def download(video_url, output_filename='audio.mp4'):
|
def download(video_url, output_filename='audio.mp4'):
|
||||||
try:
|
try:
|
||||||
print("Downloading audio...")
|
print("Downloading audio...")
|
||||||
|
|
||||||
yt = YouTube(video_url)
|
yt = YouTube(video_url)
|
||||||
audio_stream = yt.streams.get_audio_only()
|
audio_stream = yt.streams.get_audio_only()
|
||||||
audio_filename = audio_stream.download(filename=output_filename)
|
audio_filename = audio_stream.download(filename=output_filename)
|
||||||
|
|
||||||
print(f"Downloaded audio.")
|
print(f"Downloaded audio.")
|
||||||
return audio_filename
|
return audio_filename
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -49,6 +53,7 @@ def transcription(OPENAI_API_KEY, audio_filename):
|
|||||||
def summary(OPENAI_API_KEY, transcript):
|
def summary(OPENAI_API_KEY, transcript):
|
||||||
try:
|
try:
|
||||||
print("Summarizing transcript...")
|
print("Summarizing transcript...")
|
||||||
|
|
||||||
client = OpenAI(api_key=OPENAI_API_KEY)
|
client = OpenAI(api_key=OPENAI_API_KEY)
|
||||||
stream = client.chat.completions.create(
|
stream = client.chat.completions.create(
|
||||||
model="gpt-4",
|
model="gpt-4",
|
||||||
@@ -72,7 +77,9 @@ def summary(OPENAI_API_KEY, transcript):
|
|||||||
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.")
|
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}")
|
||||||
@@ -83,6 +90,7 @@ def main():
|
|||||||
try:
|
try:
|
||||||
OPENAI_API_KEY = get_api_key()
|
OPENAI_API_KEY = get_api_key()
|
||||||
video_url = str(input("Video url: "))
|
video_url = str(input("Video url: "))
|
||||||
|
|
||||||
if OPENAI_API_KEY is not None:
|
if OPENAI_API_KEY is not None:
|
||||||
audio_filename = download(video_url)
|
audio_filename = download(video_url)
|
||||||
if audio_filename is not None:
|
if audio_filename is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user