Skip to content

Instantly share code, notes, and snippets.

@johndpope
Forked from svpino/lemur.py
Created August 2, 2023 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johndpope/ce0a2d9b915ab3e90062491c0046fe9c to your computer and use it in GitHub Desktop.
Save johndpope/ce0a2d9b915ab3e90062491c0046fe9c to your computer and use it in GitHub Desktop.
import os
import assemblyai as aai
from pytube import YouTube
aai.settings.api_key = "INSERT YOUR API KEY HERE"
youtube_url = "https://www.youtube.com/watch?v=f94wKh70cOY"
# Let's download the YouTube video
youtube = YouTube(youtube_url)
audio = youtube.streams.filter(only_audio=True).first()
filename = os.path.basename(audio.download())
# We can now transcribe it
transcriber = aai.Transcriber()
transcript = transcriber.transcribe(filename)
print(transcript.text)
# This will summarize the video
summary = transcript.lemur.summarize(
context="A magician performing a magic trick"
)
print(summary.response)
# Now we can ask questions about the video
questions = [
aai.LemurQuestion(question="What is the name of the magician?"),
aai.LemurQuestion(question="What are the names of the participants?"),
aai.LemurQuestion(question="What is the magic trick about?"),
]
answers = transcript.lemur.question(questions)
for answer in answers.response:
print(f"Question: {answer.question}")
print(f"Answer: {answer.answer}")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment