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.
'''
如果您有任何問題、建議或想討論這個項目,請隨時與我聯絡:
我對合作持開放態度,並且很樂意聯繫!
米爾·阿卜杜拉·亞瑟