Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +60 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
|
| 4 |
+
load_dotenv() ##load all the nevironment variables
|
| 5 |
+
import os
|
| 6 |
+
import google.generativeai as genai
|
| 7 |
+
|
| 8 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 9 |
+
|
| 10 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 11 |
+
|
| 12 |
+
prompt ="""
|
| 13 |
+
You are Youtube video transcripter to help write a newsletter from the video given.
|
| 14 |
+
You will be taking the transcript text and summarizing the entire video and providing the detailed
|
| 15 |
+
summary in paragraph with each sub section highlighted with a title of news or update.
|
| 16 |
+
Mention all the news and updates in different sections .
|
| 17 |
+
keep the tone engaging and wtiring style formal
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
## getting the transcript data from yt videos
|
| 24 |
+
def extract_transcript_details(youtube_video_url):
|
| 25 |
+
try:
|
| 26 |
+
video_id=youtube_video_url.split("=")[1]
|
| 27 |
+
|
| 28 |
+
transcript_text=YouTubeTranscriptApi.get_transcript(video_id)
|
| 29 |
+
|
| 30 |
+
transcript = ""
|
| 31 |
+
for i in transcript_text:
|
| 32 |
+
transcript += " " + i["text"]
|
| 33 |
+
|
| 34 |
+
return transcript
|
| 35 |
+
|
| 36 |
+
except Exception as e:
|
| 37 |
+
raise e
|
| 38 |
+
|
| 39 |
+
## getting the summary based on Prompt from Google Gemini Pro
|
| 40 |
+
def generate_gemini_content(transcript_text,prompt):
|
| 41 |
+
|
| 42 |
+
model=genai.GenerativeModel("gemini-pro")
|
| 43 |
+
response=model.generate_content(prompt+transcript_text)
|
| 44 |
+
return response.text
|
| 45 |
+
|
| 46 |
+
st.title("AI Video Summarizer")
|
| 47 |
+
youtube_link = st.text_input("Enter YouTube Video Link:")
|
| 48 |
+
|
| 49 |
+
if youtube_link:
|
| 50 |
+
video_id = youtube_link.split("=")[1]
|
| 51 |
+
print(video_id)
|
| 52 |
+
st.image(f"http://img.youtube.com/vi/{video_id}/0.jpg", use_column_width=True)
|
| 53 |
+
|
| 54 |
+
if st.button("Generate Notes"):
|
| 55 |
+
transcript_text=extract_transcript_details(youtube_link)
|
| 56 |
+
|
| 57 |
+
if transcript_text:
|
| 58 |
+
summary=generate_gemini_content(transcript_text,prompt)
|
| 59 |
+
st.markdown("## Detailed Notes:")
|
| 60 |
+
st.write(summary)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
youtube_transcript_api
|
| 2 |
+
streamlit
|
| 3 |
+
google-generativeai
|
| 4 |
+
python-dotenv
|
| 5 |
+
pathlib
|