Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 4, 2025
1 parent 853fe1c commit 6d70287
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion youtube_summary/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Youtube Summary

This notebook can be used as a template to summarise YouTube videos. It was orignally
This notebook can be used as a template to summarise YouTube videos. It was originally
used to fetch summaries for some [keyboard reviews](https://www.youtube.com/playlist?list=PLGj5nRqy15j93TD0iReqfLL9lU1lZFEs6) but the notebook itself can be adapted
for many other use-cases too.

Expand Down
37 changes: 22 additions & 15 deletions youtube_summary/youtube_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ def _():
from yt_dlp import YoutubeDL
from pathlib import Path

def download_yt(yt_url: str):
def download_yt(yt_url: str):
yt_id = yt_url[-11:]
video_path = f"{yt_id}.m4a"

ydl_opts = {
'format': 'm4a/bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'm4a',
}]
"format": "m4a/bestaudio/best",
"postprocessors": [
{
"key": "FFmpegExtractAudio",
"preferredcodec": "m4a",
}
],
}

if not Path(video_path).exists():
Expand All @@ -50,12 +52,14 @@ def download_yt(yt_url: str):
vid.rename(video_path)
else:
print("Video has been downloaded already")

return Path, YoutubeDL, cv2, download_yt, plt


@app.cell
def _():
import marimo as mo

return (mo,)


Expand Down Expand Up @@ -104,18 +108,19 @@ def _():
import instructor
from pydantic import BaseModel


class YouTubeOutput(BaseModel):
"""
Output of a YouTube video that reviews ergonomic keyboards.
Make sure that you have a clear summary that highlights some of the findings. Refer to the reviewer as "me" and write as if it was written by the reviewer. But not in the present tense, it needs to be past tense. Avoid a formal style, write as if it was written on an informal tech-blog. Also make sure that you create a sequences of pros and cons of the keyboard. No more than 4 pros and 4 cons. Also add a oneliner tldr for the review, typically you can just copy what is in the title. The name of the keyboard should also include the brand if there is one.
Make sure that you have a clear summary that highlights some of the findings. Refer to the reviewer as "me" and write as if it was written by the reviewer. But not in the present tense, it needs to be past tense. Avoid a formal style, write as if it was written on an informal tech-blog. Also make sure that you create a sequences of pros and cons of the keyboard. No more than 4 pros and 4 cons. Also add a oneliner tldr for the review, typically you can just copy what is in the title. The name of the keyboard should also include the brand if there is one.
"""

summary: str
pros: List[str]
cons: List[str]
tldr: str
keyboard_name: str

return BaseModel, List, YouTubeOutput, instructor


Expand All @@ -136,7 +141,9 @@ def _(instructor):

@app.cell
def _(mo):
mo.md("Once the downloading/parsing/generating is done, you can see the results below together with a 'copy to clipboard' button.")
mo.md(
"Once the downloading/parsing/generating is done, you can see the results below together with a 'copy to clipboard' button."
)
return


Expand Down Expand Up @@ -181,7 +188,6 @@ def _(
""")


with mo.status.spinner(subtitle="Running LLM ...") as _spinner:
response = client.chat.completions.create(
model="claude-3-5-sonnet-20241022",
Expand All @@ -195,14 +201,14 @@ def _(
response_model=YouTubeOutput,
)
rendered = template.render(
summary=response.summary,
pros=response.pros,
summary=response.summary,
pros=response.pros,
cons=response.cons,
title=info["title"],
title=info["title"],
thumbnail=info["thumbnail"],
keyboard_name=response.keyboard_name,
tldr=response.tldr,
video_idx=f"{text_input.value[-11:]}"
tldr=response.tldr,
video_idx=f"{text_input.value[-11:]}",
)
clipboard_btn = CopyToClipboard(rendered)

Expand All @@ -223,6 +229,7 @@ def _(
@app.cell
def _():
from wigglystuff import CopyToClipboard

return (CopyToClipboard,)


Expand Down

0 comments on commit 6d70287

Please sign in to comment.