mazed commited on
Commit
b1c4d73
·
verified ·
1 Parent(s): 7879a6e

Upload 3 files

Browse files
Files changed (3) hide show
  1. .env +1 -0
  2. app.py +55 -0
  3. requirements.txt +5 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY = "AIzaSyBBrePLC0eqi2LTVio-a7fyFKDqnoB9HdM"
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from dotenv import load_dotenv
4
+ load_dotenv() # load all the environment variables
5
+
6
+ import google.generativeai as genai
7
+ from youtube_transcript_api import YouTubeTranscriptApi
8
+
9
+ # Configure api
10
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
11
+
12
+ prompt=""" You are Youtube video summarizer. You will be taking the transcript text
13
+ and summarizing the entire video and providing the importance summary in points
14
+ within 250 words. The transcript text will be appended here: """
15
+
16
+ # Define function to get transcript from youtube video
17
+ def extract_transcript(youtube_video_url):
18
+ try:
19
+ video_id=youtube_video_url.split("=")[1]
20
+ transcript_text=YouTubeTranscriptApi.get_transcript(video_id)
21
+
22
+ transcript=""
23
+ for i in transcript_text:
24
+ transcript += " "+ i["text"]
25
+ return transcript
26
+ except Exception as e:
27
+ raise e
28
+
29
+ # Define function to summarize the transcript
30
+ def generate_gemini_content(transcript,prompt):
31
+ model=genai.GenerativeModel("gemini-pro")
32
+ response=model.generate_content(prompt+transcript)
33
+ return response.text
34
+
35
+
36
+ # Initialize streamlit app
37
+ st.set_page_config(page_title="YTsummarizer")
38
+
39
+ # App name
40
+ st.markdown("<h4 style='text-align: center;'>Youtube Video Summarizer</h4>", unsafe_allow_html=True)
41
+
42
+ # Input
43
+ youtube_link=st.text_input(" ", key="input", placeholder="Enter Youtube video link")
44
+
45
+ if youtube_link:
46
+ video_id=youtube_link.split("=")[1].split("&")[0]
47
+ print(video_id)
48
+ st.image(f"http://img.youtube.com/vi/{video_id}/0.jpg", use_column_width=True)
49
+
50
+ if st.button("Summarize"):
51
+ transcript=extract_transcript(youtube_link)
52
+
53
+ if transcript:
54
+ summary=generate_gemini_content(transcript,prompt)
55
+ st.write(summary)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ youtube_transcript_api
2
+ streamlit
3
+ google-generativeai
4
+ python-dotenv
5
+ pathlib