Created
July 11, 2023 11:06
-
-
Save seidtgeist/13cd3228a588201eaaae6af075c5f156 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# First argument is video URL or ID | |
# Second argument is the question | |
# set -uo pipefail | |
# Get video ID from URL | |
VIDEO_ID=$(echo $1 | cut -d'=' -f 2) | |
# Get question from args | |
QUESTION=$2 | |
AUDIO="whisper_$VIDEO_ID.wav" | |
TITLE_FILE="$VIDEO_ID.title" | |
DESCRIPTION_FILE="$VIDEO_ID.desc" | |
TAGS_FILE="$VIDEO_ID.tags" | |
UPLOADER_FILE="$VIDEO_ID.uploader" | |
JSON_FILE="$VIDEO_ID.info.json" | |
TEXT_FILE="$AUDIO.txt" | |
# Download audio | |
if [ ! -e $AUDIO ]; then | |
yt-dlp --write-info-json -f bestaudio --extract-audio $1 -o "%(id)s.%(ext)s" | |
# Convert video to 16 | |
ffmpeg -i $VIDEO_ID.opus -f wav -ar 16000 $AUDIO | |
fi | |
# Create prompt | |
UPLOADER=$(cat $JSON_FILE | jq -r '.uploader') | |
TITLE=$(cat $JSON_FILE | jq -r '.title') | |
DESCRIPTION=$(cat $JSON_FILE | jq -r '.description') | |
TAGS=$(cat $JSON_FILE | jq -r '.tags[]') | |
PROMPT=$(cat << EOF | |
Please transcribe the following video using the following meta data for your vocabulary. | |
Title: $TITLE | |
Uploader: $UPLOADER | |
Tags: $TAGS | |
Description: | |
$DESCRIPTION | |
EOF | |
) | |
# Remove URLs from prompt | |
PROMPT=$(echo $PROMPT | sed -E 's/http[^ ]+//g') | |
# # Transcribe audio | |
if [ ! -e $TEXT_FILE ]; then | |
../whisper.cpp/main \ | |
-m ../whisper.cpp/models/ggml-large.bin \ | |
-l auto \ | |
-tr \ | |
--prompt "$PROMPT" \ | |
-otxt \ | |
$AUDIO | |
fi | |
# define multline string variable using EOF | |
# To add in system or user prompt: | |
# | |
# - you must only use information provided in the transcript | |
# - you may also rely on common knowledge | |
# - if you rely on specialized knowledge that does not appear in the transcript, you must explicitly say so | |
GPT_PROMPT=$(cat << EOF | |
# Video meta data | |
Title: $TITLE | |
Uploader: $UPLOADER | |
Tags: $TAGS | |
Description: | |
$DESCRIPTION | |
# Video transcript | |
$(cat $TEXT_FILE) | |
# Instructions | |
$QUESTION | |
Please follow the instructions (if unclear, assume answering a question) based on the youtube video transcript and meta data. | |
EOF | |
) | |
# Send transcript to LLM along with question | |
pipx run llm -m gpt4 "$GPT_PROMPT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment