File size: 1,997 Bytes
d03c658 3b01476 d03c658 e672f4a d03c658 3b01476 d03c658 3b01476 d03c658 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
import streamlit as st
import os
import google.generativeai as genai
import re
def extract_video_id(url):
# Regular expression pattern to match the video ID
pattern = r'(?<=/|v=|vi/|youtu\.be/|embed/)[^#&?]*'
match = re.search(pattern, url)
if match:
return match.group(0)
else:
return None
from youtube_transcript_api import YouTubeTranscriptApi
secret_key = os.getenv("SECRET_KEY")
genai.configure(api_key=secret_key)
prompt="""You are Yotube video summarizer. You will be taking the transcript text
and summarizing the entire video and providing the important summary in points
within 250 words. Please provide the summary of the text given here: """
## getting the transcript data from yt videos
def extract_transcript_details(youtube_video_url):
try:
# video_id=youtube_video_url.split("=")[1]
video_id=extract_video_id(youtube_link)
transcript_text=YouTubeTranscriptApi.get_transcript(video_id)
transcript = ""
for i in transcript_text:
transcript += " " + i["text"]
return transcript
except Exception as e:
raise e
## getting the summary based on Prompt from Google Gemini Pro
def generate_gemini_content(transcript_text,prompt):
model=genai.GenerativeModel("gemini-pro")
response=model.generate_content(prompt+transcript_text)
return response.text
st.title("YouTube Transcript to Detailed Notes Converter")
youtube_link = st.text_input("Enter YouTube Video Link:")
if youtube_link:
# video_id = youtube_link.split("=")[1]
video_id=extract_video_id(youtube_link)
print(video_id)
st.image(f"http://img.youtube.com/vi/{video_id}/0.jpg", use_column_width=True)
if st.button("Get Detailed Notes"):
transcript_text=extract_transcript_details(youtube_link)
if transcript_text:
summary=generate_gemini_content(transcript_text,prompt)
st.markdown("## Detailed Notes:")
st.write(summary)
|