|
import streamlit as st |
|
|
|
import os |
|
import google.generativeai as genai |
|
|
|
import re |
|
|
|
|
|
def parseYoutubeURL(url): |
|
url=str(url) |
|
data = re.findall(r"(?:v=|\/)([0-9A-Za-z_-]{11}).*", url) |
|
if data: |
|
return data[0] |
|
return "" |
|
|
|
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: """ |
|
|
|
|
|
|
|
def extract_transcript_details(youtube_video_url): |
|
try: |
|
|
|
video_id=parseYoutubeURL(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 |
|
|
|
|
|
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=parseYoutubeURL(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) |
|
|
|
|
|
|
|
|
|
|
|
|