Summarizing Youtube Videos with OpenAI Whisper and GPT 3
1.0.0
此 Python 脚本允许您使用 OpenAI 的 Whisper 进行音频转录,并使用 GPT 生成简洁的视频摘要来总结 YouTube 视频。该管道涉及下载 YouTube 视频的音频,使用 Whisper 进行转录,然后使用 GPT 生成摘要。
在开始之前,请确保您拥有必要的 Python 库和 OpenAI API 密钥:
whisper
库(用于音频转录)openai
库(适用于 GPT)pytube
库(用于下载 YouTube 视频)您还应该将 OpenAI API 密钥设置为环境变量。
该脚本首先从 YouTube 视频下载音频。它使用pytube
库来获取视频,选择纯音频流,并将其保存为音频文件。
youtube_video = YouTube ( YOUTUBE_VIDEO_URL )
streams = youtube_video . streams . filter ( only_audio = True )
# taking first object of lowest quality
stream = streams . first ()
stream . download ( filename = OUTPUT_AUDIO )
接下来,使用 Whisper 模型转录音频。 Whisper库用于加载Whisper模型、转录音频并获取转录本。
model = whisper . load_model ( WHISPER_MODEL )
transcript = model . transcribe ( OUTPUT_AUDIO . as_posix ())
transcript = transcript [ 'text' ]
print ( f'Transcript generated: n { transcript } ' )
然后,该脚本使用 GPT 生成转录文本的简明摘要。它提供系统提示和用户提示来指示 GPT 生成有意义的摘要。
model = whisper . load_model ( WHISPER_MODEL )
transcript = model . transcribe ( OUTPUT_AUDIO . as_posix ())
transcript = transcript [ 'text' ]
print ( f'Transcript generated: n { transcript } ' ) system_prompt = "I would like for you to assume the role of a Life Coach"
user_prompt = f"""Generate a concise summary of the text below.
Text: { transcript }
Add a title to the summary.
Make sure your summary has useful and true information about the main points of the topic.
Begin with a short introduction explaining the topic. If you can, use bullet points to list important details,
and finish your summary with a concluding sentence"""
#
print ( 'summarizing ... ' )
response = openai . ChatCompletion . create (
model = 'gpt-3.5-turbo-16k' ,
messages = [
{ 'role' : 'system' , 'content' : system_prompt },
{ 'role' : 'user' , 'content' : user_prompt }
],
max_tokens = 4096 ,
temperature = 1
)
#
summary = response [ 'choices' ][ 0 ][ 'message' ][ 'content' ]
'''
Title: The Realities of Fame and the Importance of Being True to Yourself
Summary:
This conversation revolves around the concept of fame and the misconceptions associated with it. The speaker emphasizes that despite the glitz and glamour of Hollywood, celebrities are just like normal people, and it is unrealistic to expect them to maintain a constant facade of perfection. The conversation also explores the speaker's personal journey of self-discovery and his desire to use his success for something more meaningful. The importance of forgiveness, both towards others and oneself, is highlighted. The speaker suggests that being of service to others can bring fulfillment and challenges the notion that fame should be pursued endlessly. The conversation concludes by discussing the distinction between fame and celebrity, and the importance of staying true to oneself amidst external scrutiny. The speaker admires the courage of the person he is speaking to for being relentlessly authentic in the public eye.
Introduction: This conversation delves into the realities of fame and the speaker's desire to go beyond the superficialities of success.
- Fame in Hollywood and the normalcy of celebrities
4. The treadmill of seeking more fame:
- Rejecting the pursuit of increasing celebrity status in the twilight of one's life
- Encouraging a focus on personal growth and meaningful experiences
5. Authenticity and self-discovery:
- Differentiating between fame as external circumstances and one's true self
- Acknowledging the courage required to maintain authenticity in the face of scrutiny
Conclusion: The conversation highlights the speaker's insights on fame, the importance of self-discovery, and the need to stay true to oneself in the public eye.
'''
如果您有任何问题、建议或想讨论这个项目,请随时与我联系:
我对合作持开放态度,并且很乐意联系!
米尔·阿卜杜拉·亚瑟