Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,7 +24,7 @@ import pathlib
|
|
| 24 |
import pandas
|
| 25 |
import numpy
|
| 26 |
import textblob
|
| 27 |
-
import
|
| 28 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 29 |
import google.generativeai as genai
|
| 30 |
import requests
|
|
@@ -64,7 +64,7 @@ def install_missing_packages():
|
|
| 64 |
|
| 65 |
install_missing_packages()
|
| 66 |
import os
|
| 67 |
-
import
|
| 68 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 69 |
from dotenv import load_dotenv
|
| 70 |
import google.generativeai as genai
|
|
@@ -73,11 +73,8 @@ import requests
|
|
| 73 |
from transformers import pipeline
|
| 74 |
from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
|
| 75 |
from pytube import YouTube
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
|
| 79 |
-
from pytube import YouTube
|
| 80 |
-
import gradio as gr
|
| 81 |
|
| 82 |
hf_token = os.getenv("HF_TOKEN")
|
| 83 |
if hf_token:
|
|
@@ -85,6 +82,12 @@ if hf_token:
|
|
| 85 |
else:
|
| 86 |
raise ValueError("HF_TOKEN environment variable not set.")
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
# Function to extract transcript from a YouTube video
|
| 89 |
def extract_transcript(youtube_video_url):
|
| 90 |
try:
|
|
@@ -127,38 +130,32 @@ def summarize_transcript(transcript_text):
|
|
| 127 |
if chunk.strip():
|
| 128 |
out = summarizer(chunk, max_length=130, min_length=30, do_sample=False)
|
| 129 |
summarized_text.append(out[0]['summary_text'])
|
| 130 |
-
|
| 131 |
return " ".join(summarized_text)
|
| 132 |
except Exception as e:
|
| 133 |
return f"Error during summarization: {str(e)}"
|
| 134 |
|
| 135 |
-
#
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
outputs=[transcript_output, summary_output]
|
| 160 |
-
)
|
| 161 |
-
|
| 162 |
-
# Launch Gradio App
|
| 163 |
-
if __name__ == "__main__":
|
| 164 |
-
demo.launch()
|
|
|
|
| 24 |
import pandas
|
| 25 |
import numpy
|
| 26 |
import textblob
|
| 27 |
+
import streamlit as st
|
| 28 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 29 |
import google.generativeai as genai
|
| 30 |
import requests
|
|
|
|
| 64 |
|
| 65 |
install_missing_packages()
|
| 66 |
import os
|
| 67 |
+
import streamlit as st
|
| 68 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 69 |
from dotenv import load_dotenv
|
| 70 |
import google.generativeai as genai
|
|
|
|
| 73 |
from transformers import pipeline
|
| 74 |
from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
|
| 75 |
from pytube import YouTube
|
| 76 |
+
|
| 77 |
+
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
hf_token = os.getenv("HF_TOKEN")
|
| 80 |
if hf_token:
|
|
|
|
| 82 |
else:
|
| 83 |
raise ValueError("HF_TOKEN environment variable not set.")
|
| 84 |
|
| 85 |
+
import os
|
| 86 |
+
import streamlit as st
|
| 87 |
+
from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
|
| 88 |
+
from pytube import YouTube
|
| 89 |
+
from transformers import pipeline
|
| 90 |
+
|
| 91 |
# Function to extract transcript from a YouTube video
|
| 92 |
def extract_transcript(youtube_video_url):
|
| 93 |
try:
|
|
|
|
| 130 |
if chunk.strip():
|
| 131 |
out = summarizer(chunk, max_length=130, min_length=30, do_sample=False)
|
| 132 |
summarized_text.append(out[0]['summary_text'])
|
| 133 |
+
|
| 134 |
return " ".join(summarized_text)
|
| 135 |
except Exception as e:
|
| 136 |
return f"Error during summarization: {str(e)}"
|
| 137 |
|
| 138 |
+
# Streamlit App Design
|
| 139 |
+
st.title("YouTube Video Summarizer")
|
| 140 |
+
|
| 141 |
+
# Input field for YouTube URL
|
| 142 |
+
youtube_url = st.text_input("Enter YouTube Video URL", "")
|
| 143 |
+
|
| 144 |
+
if st.button("Summarize Transcript"):
|
| 145 |
+
if youtube_url:
|
| 146 |
+
with st.spinner("Extracting transcript..."):
|
| 147 |
+
transcript = extract_transcript(youtube_url)
|
| 148 |
+
|
| 149 |
+
if transcript.startswith("Error"):
|
| 150 |
+
st.error(transcript)
|
| 151 |
+
else:
|
| 152 |
+
st.subheader("Original Transcript")
|
| 153 |
+
st.text_area("Transcript", transcript, height=200)
|
| 154 |
+
|
| 155 |
+
with st.spinner("Summarizing transcript..."):
|
| 156 |
+
summarized_text = summarize_transcript(transcript)
|
| 157 |
+
|
| 158 |
+
st.subheader("Summarized Text")
|
| 159 |
+
st.text_area("Summary", summarized_text, height=200)
|
| 160 |
+
else:
|
| 161 |
+
st.error("Please enter a valid YouTube URL.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|