Ce script Python vous permet de résumer des vidéos YouTube à l'aide de Whisper d'OpenAI pour la transcription audio et de GPT pour générer des résumés vidéo concis. Le pipeline consiste à télécharger l'audio d'une vidéo YouTube, à la transcrire avec Whisper, puis à générer un résumé à l'aide de GPT.
Avant de commencer, assurez-vous de disposer des bibliothèques Python nécessaires et d'une clé API OpenAI :
whisper
(pour la transcription audio)openai
(pour GPT)pytube
(pour télécharger des vidéos YouTube)Vous devez également configurer votre clé API OpenAI en tant que variable d'environnement.
Le script commence par télécharger l'audio d'une vidéo YouTube. Il utilise la bibliothèque pytube
pour récupérer la vidéo, sélectionner le flux audio uniquement et l'enregistrer en tant que fichier audio.
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 )
Ensuite, l'audio est transcrit à l'aide du modèle Whisper. La bibliothèque Whisper est utilisée pour charger le modèle Whisper, transcrire l'audio et obtenir la transcription.
model = whisper . load_model ( WHISPER_MODEL )
transcript = model . transcribe ( OUTPUT_AUDIO . as_posix ())
transcript = transcript [ 'text' ]
print ( f'Transcript generated: n { transcript } ' )
Le script utilise ensuite GPT pour générer un résumé concis du texte transcrit. Il fournit une invite système et une invite utilisateur pour demander à GPT de générer un résumé significatif.
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.
'''
Si vous avez des questions, des suggestions, ou si vous souhaitez discuter de ce projet, n'hésitez pas à me contacter :
Je suis ouvert à la collaboration et serais heureux de me connecter !
Mir Abdallah Yaser