Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,85 +1,52 @@
|
|
| 1 |
-
|
| 2 |
-
import streamlit as st
|
| 3 |
-
import http.client
|
| 4 |
-
import json
|
| 5 |
-
import google.generativeai as genai
|
| 6 |
-
|
| 7 |
-
# Configure the Generative AI API
|
| 8 |
-
genai.configure(api_key="AIzaSyDiGhxeTJVQoK8jyRge6aaZGg7CrLq0zGk")
|
| 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 |
-
else:
|
| 54 |
-
return "Failed to generate summary."
|
| 55 |
-
|
| 56 |
-
# Streamlit UI
|
| 57 |
-
st.title("YouTube Video Summarizer")
|
| 58 |
-
|
| 59 |
-
video_url = st.text_input("Enter YouTube Video URL:")
|
| 60 |
-
|
| 61 |
-
if st.button("Summarize"):
|
| 62 |
-
if video_url:
|
| 63 |
-
try:
|
| 64 |
-
# Fetch subtitles
|
| 65 |
-
st.info("Fetching subtitles...")
|
| 66 |
-
transcript = fetch_youtube_subtitles(video_url)
|
| 67 |
-
|
| 68 |
-
if transcript:
|
| 69 |
-
# Display fetched subtitles
|
| 70 |
-
st.subheader("Fetched Transcript:")
|
| 71 |
-
st.text_area("Transcript", transcript, height=200)
|
| 72 |
-
|
| 73 |
-
# Summarize the transcript using Gemini
|
| 74 |
-
st.info("Summarizing transcript...")
|
| 75 |
-
summary = get_gemini_response(f"Summarize the following transcript: {transcript}")
|
| 76 |
-
|
| 77 |
-
# Display the summary
|
| 78 |
-
st.subheader("Summary:")
|
| 79 |
-
st.write(summary)
|
| 80 |
-
else:
|
| 81 |
-
st.warning("No subtitles found for the video.")
|
| 82 |
-
except Exception as e:
|
| 83 |
-
st.error(f"An error occurred: {e}")
|
| 84 |
-
else:
|
| 85 |
-
st.error("Please enter a valid YouTube URL.")
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import http.client
|
| 4 |
+
import json
|
| 5 |
+
import google.generativeai as genai
|
| 6 |
+
|
| 7 |
+
# Configure the Generative AI API
|
| 8 |
+
genai.configure(api_key="AIzaSyDiGhxeTJVQoK8jyRge6aaZGg7CrLq0zGk")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# Function to generate summary using Generative AI
|
| 13 |
+
def get_gemini_response(prompt):
|
| 14 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 15 |
+
response = model.generate_content(prompt)
|
| 16 |
+
if hasattr(response.candidates[0], "content"):
|
| 17 |
+
return response.candidates[0].content
|
| 18 |
+
else:
|
| 19 |
+
return "Failed to generate summary."
|
| 20 |
+
|
| 21 |
+
# Streamlit App
|
| 22 |
+
st.title("YouTube Video Summarizer")
|
| 23 |
+
|
| 24 |
+
# Input for YouTube video URL
|
| 25 |
+
video_url = st.text_input("Enter YouTube Video URL:")
|
| 26 |
+
|
| 27 |
+
if st.button("Generate Summary"):
|
| 28 |
+
if "youtube.com" in video_url or "youtu.be" in video_url:
|
| 29 |
+
# Extract video ID
|
| 30 |
+
video_id = video_url.split("v=")[-1].split("&")[0] if "v=" in video_url else video_url.split("/")[-1]
|
| 31 |
+
|
| 32 |
+
# Fetch transcript
|
| 33 |
+
with st.spinner("Fetching transcript..."):
|
| 34 |
+
api_url = "https://resumegenie-c0pc.onrender.com/fetch_captions"
|
| 35 |
+
try:
|
| 36 |
+
response = requests.post(api_url, json={"video_id": video_id})
|
| 37 |
+
if response.status_code == 200:
|
| 38 |
+
transcript_data = response.json().get("transcript")
|
| 39 |
+
transcript = " ".join([item["text"] for item in transcript_data])
|
| 40 |
+
|
| 41 |
+
# Generate summary using Gemini
|
| 42 |
+
with st.spinner("Generating summary..."):
|
| 43 |
+
summary = get_gemini_response(f"Summarize the following text: {transcript}")
|
| 44 |
+
st.subheader("Video Summary")
|
| 45 |
+
st.write(summary)
|
| 46 |
+
else:
|
| 47 |
+
st.error(f"Error: {response.json().get('detail', 'Unknown error')}")
|
| 48 |
+
except Exception as e:
|
| 49 |
+
st.error(f"Error: {str(e)}")
|
| 50 |
+
else:
|
| 51 |
+
st.error("Invalid YouTube URL.")
|
| 52 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|