Skip to content

Commit

Permalink
Update YouTube transcript summarization prompt and handle "youtu.be/i…
Browse files Browse the repository at this point in the history
…d" URL format
  • Loading branch information
ket0x4 committed Jun 16, 2024
1 parent f1e1e34 commit b52a9d6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ketard.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async def handle_ket_command(bot, message):
finally:
queue_count -= 1


# handle summarize command
@bot.on_message(filters.command(["sum", "vid", "video", "youtube", "transcript", "summarize"]))
async def handle_sum_command(bot, message):
global queue_count
Expand All @@ -155,11 +155,11 @@ async def handle_sum_command(bot, message):
return

try:
# YouTube URL'sini mesajdan al
# Get URL
url = message.text.split(" ")[1]
video_id = None

# YouTube video ID'sini çözümleme
# Parse Youtube URL
if "youtube.com" in url:
video_id = url.split("v=")[1]
elif "youtu.be" in url:
Expand All @@ -171,19 +171,19 @@ async def handle_sum_command(bot, message):
return

try:
# Videonun transkriptini al
# Get transcript
transcript = YouTubeTranscriptApi.get_transcript(video_id)
if not transcript:
await message.reply_text(
f"Unable to retrieve the transcript for the video.", quote=True
)
return

# Özetleme prompt'u oluşturma
# Prepare prompt
lmm_prompt = "This is a transcript of a YouTube video: summarize and make it short. Exclude sponsored sections and intro/outro."
prompt = lmm_prompt + " ".join([item["text"] for item in transcript])

# Transkripti özetleme
# summarize
response_header = f"**Summarized Video:** `{url}`\n\n"
start_time = time.time()
response = response_header + ollama.invoke(prompt)
Expand Down

0 comments on commit b52a9d6

Please sign in to comment.