Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,53 +1,52 @@
|
|
| 1 |
-
from dotenv import load_dotenv
|
| 2 |
-
load_dotenv()
|
| 3 |
-
import streamlit as st
|
| 4 |
-
import os
|
| 5 |
-
import google.generativeai as genai
|
| 6 |
-
from PIL import Image
|
| 7 |
-
import
|
| 8 |
-
import
|
| 9 |
-
import
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
video_id =
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
response
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
st.
|
| 41 |
-
st.
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
st.markdown("## Summary:")
|
| 53 |
st.write(response)
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
load_dotenv()
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import os
|
| 5 |
+
import google.generativeai as genai
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import io
|
| 8 |
+
import base64
|
| 9 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 10 |
+
|
| 11 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 12 |
+
# load gemini model
|
| 13 |
+
|
| 14 |
+
prompt="""You are Yotube video summarizer. You will be taking the transcript text
|
| 15 |
+
and summarizing the entire video and providing the important summary in points
|
| 16 |
+
within 250 words. Please provide the summary of the text given here: """
|
| 17 |
+
|
| 18 |
+
def get_youtube_transcript(video_url):
|
| 19 |
+
try:
|
| 20 |
+
video_id = video_url.split("=")[1]
|
| 21 |
+
# video_id = video_id.split("&")[0]
|
| 22 |
+
print(video_id)
|
| 23 |
+
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
| 24 |
+
transcript_text = ""
|
| 25 |
+
for i in transcript:
|
| 26 |
+
transcript_text += " " + i['text']
|
| 27 |
+
return transcript_text
|
| 28 |
+
except Exception as e:
|
| 29 |
+
raise e
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def get_gemini_response(transcript_text,prompt):
|
| 33 |
+
model=genai.GenerativeModel("gemini-pro")
|
| 34 |
+
response=model.generate_content(prompt+transcript_text)
|
| 35 |
+
return response.text
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
st.title("Youtube Transcript to detailed summary")
|
| 40 |
+
st.markdown("This app uses gemini pro to generate a detailed summary of the transcript of a youtube video")
|
| 41 |
+
video_url = st.text_input("Enter the youtube video url")
|
| 42 |
+
|
| 43 |
+
if video_url:
|
| 44 |
+
video_id=video_url.split("=")[1]
|
| 45 |
+
print(video_id)
|
| 46 |
+
st.image(f"https://img.youtube.com/vi/{video_id}/0.jpg",use_column_width=True)
|
| 47 |
+
if st.button("Generate Summary"):
|
| 48 |
+
transcript_text = get_youtube_transcript(video_url)
|
| 49 |
+
if transcript_text:
|
| 50 |
+
response = get_gemini_response(transcript_text,prompt)
|
| 51 |
+
st.markdown("## Summary:")
|
|
|
|
| 52 |
st.write(response)
|