import streamlit as st import os import google.generativeai as genai from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled from huggingface_hub import hf_hub_download # Configure the API key from Hugging Face's Secrets Management google_api_key = os.getenv("GOOGLE_API_KEY") genai.configure(api_key=google_api_key) prompt = """You are a YouTube 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 YouTube videos def extract_transcript_details(youtube_video_url): try: video_id = youtube_video_url.split("=")[1] # Try fetching the transcript transcript_text = YouTubeTranscriptApi.get_transcript(video_id) transcript = "" for i in transcript_text: transcript += " " + i["text"] return transcript except TranscriptsDisabled: # Handle case when transcripts are disabled for the video st.error("Transcripts are disabled for this video. Please ensure subtitles are enabled.") return None except Exception as e: # Handle any other errors st.error(f"An error occurred: {e}") return None # Getting the summary based on the 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] 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)