Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import re

import google.generativeai as genai
import streamlit as st
from dotenv import load_dotenv
from youtube_transcript_api import YouTubeTranscriptApi
import google.generativeai as genai

# Load environment variables
load_dotenv()
Expand All @@ -14,22 +16,31 @@
prompt = """Welcome, Video Summarizer! Your task is to distill the essence of a given YouTube video transcript into a concise summary. Your summary should capture the key points and essential information, presented in bullet points, within a 250-word limit. Let's dive into the provided transcript and extract the vital details for our audience."""


def get_video_id(youtube_video_url):
match = re.match(
r"^(http|https)://www\.youtube\.com/(v=|watch\?v=)([a-zA-Z0-9_-]+)", youtube_video_url)
if match:
return match.group(3)
else:
raise ValueError("Invalid YouTube URL format.")

# Function to extract transcript details from a YouTube video URL


def extract_transcript_details(youtube_video_url):
try:
video_id = youtube_video_url.split("=")[1]
video_id = get_video_id(youtube_video_url)
transcript_text = YouTubeTranscriptApi.get_transcript(video_id)

transcript = ""
for i in transcript_text:
transcript += " " + i["text"]

transcript = " ".join([item["text"] for item in transcript_text])
return transcript
except ConnectionError:
raise ConnectionError("Network error occurred.")
except Exception as e:
raise e


# Function to generate summary using Google Gemini Pro


def generate_gemini_content(transcript_text, prompt):
model = genai.GenerativeModel("gemini-pro")
response = model.generate_content(prompt + transcript_text)
Expand All @@ -43,8 +54,9 @@ def generate_gemini_content(transcript_text, prompt):
youtube_link = st.text_input("Enter YouTube Video Link:")

if youtube_link:
video_id = youtube_link.split("=")[1]
st.image(f"http://img.youtube.com/vi/{video_id}/0.jpg", use_column_width=True)
video_id = get_video_id(youtube_link)
st.image(
f"http://img.youtube.com/vi/{video_id}/0.jpg", use_column_width=True)

# Button to trigger summary generation
if st.button("Get Detailed Notes"):
Expand Down