Spaces:
Build error
Build error
| from dotenv import load_dotenv | |
| load_dotenv() | |
| import streamlit as st | |
| import os | |
| import google.generativeai as genai | |
| from PIL import Image | |
| import io | |
| import base64 | |
| from youtube_transcript_api import YouTubeTranscriptApi | |
| genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) | |
| # load gemini model | |
| 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 get_youtube_transcript(video_url): | |
| try: | |
| video_id = video_url.split("=")[1] | |
| # video_id = video_id.split("&")[0] | |
| print(video_id) | |
| transcript = YouTubeTranscriptApi.get_transcript(video_id) | |
| transcript_text = "" | |
| for i in transcript: | |
| transcript_text += " " + i['text'] | |
| return transcript_text | |
| except Exception as e: | |
| raise e | |
| def get_gemini_response(transcript_text,prompt): | |
| model=genai.GenerativeModel("gemini-pro") | |
| response=model.generate_content(prompt+transcript_text) | |
| return response.text | |
| st.title("Youtube Transcript to detailed summary") | |
| st.markdown("This app uses gemini pro to generate a detailed summary of the transcript of a youtube video") | |
| video_url = st.text_input("Enter the youtube video url") | |
| if video_url: | |
| video_id=video_url.split("=")[1] | |
| print(video_id) | |
| st.image(f"https://img.youtube.com/vi/{video_id}/0.jpg",use_column_width=True) | |
| if st.button("Generate Summary"): | |
| transcript_text = get_youtube_transcript(video_url) | |
| if transcript_text: | |
| response = get_gemini_response(transcript_text,prompt) | |
| st.markdown("## Summary:") | |
| st.write(response) |