-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
60 lines (43 loc) · 2.24 KB
/
app.py
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
import streamlit as st
from dotenv import load_dotenv
load_dotenv() # Load environment variables from .env file
import os
import google.generativeai as genai
from youtube_transcript_api import YouTubeTranscriptApi #it will try to idea of video and reterive all the datas from the video
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
prompt = """You are a YouTube Video Summarizer tasked with providing an in-depth analysis of a video's content. Your goal is to generate a comprehensive summary that captures the main points, key arguments, and supporting details within a 750-word limit. Please thoroughly analyze the transcript text provided and offer a detailed summary, ensuring to cover all relevant aspects of the video: """
#getting the transcript of the youtube video
def extract_transcript_details(youtube_video_url):
try:
video_id = youtube_video_url.split("=")[1]
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 form 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 the Youtube Video URL : ")
#for displaying thumbnail images
if youtube_link:
video_id = youtube_link.split("=")[1]
st.image(f"https://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)
st.markdown("---")
st.write(
"Made By Himanshu Singh [#Linkedin](https://www.linkedin.com/in/himanshu-singh01/) !"
)
st.markdown(
"More infos and :star: at [github.com/himanshugitcode/Youtube-Video-Summarizer](https://github.com/HimanshuGitCode/Youtube-Video-Summarizer) !"
)