Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,14 +10,15 @@ from textblob import TextBlob
|
|
10 |
import re
|
11 |
import nltk
|
12 |
|
13 |
-
# Ensure
|
14 |
nltk.download('punkt')
|
15 |
nltk.download('stopwords')
|
16 |
nltk.download('wordnet')
|
|
|
17 |
|
18 |
# Function to summarize text
|
19 |
def summarize_text(text, max_length=80000): # Increased max_length to 80,000
|
20 |
-
summarization_pipeline = pipeline("summarization"
|
21 |
summary = summarization_pipeline(text, max_length=max_length, min_length=100, do_sample=False)
|
22 |
return summary[0]['summary_text']
|
23 |
|
@@ -63,20 +64,6 @@ def extract_video_id(url):
|
|
63 |
break
|
64 |
return video_id
|
65 |
|
66 |
-
# Function to fetch transcript with retries
|
67 |
-
def get_transcript(video_id):
|
68 |
-
try:
|
69 |
-
# Attempt to fetch the transcript with language preference
|
70 |
-
transcript = YouTubeTranscriptApi.get_transcript(video_id, languages=['en'])
|
71 |
-
return transcript
|
72 |
-
except TranscriptsDisabled:
|
73 |
-
st.error("Transcripts are disabled for this video. Try a different one.")
|
74 |
-
except NoTranscriptFound:
|
75 |
-
st.error("No transcript found for this video. Ensure it has captions enabled.")
|
76 |
-
except Exception as e:
|
77 |
-
st.error(f"An unexpected error occurred while fetching the transcript: {str(e)}")
|
78 |
-
return None
|
79 |
-
|
80 |
# Main Streamlit app
|
81 |
def main():
|
82 |
st.title("YouTube Video Summarizer")
|
@@ -118,8 +105,9 @@ def main():
|
|
118 |
return
|
119 |
|
120 |
# Get transcript of the video
|
121 |
-
transcript = get_transcript(video_id)
|
122 |
if not transcript:
|
|
|
123 |
return
|
124 |
|
125 |
video_text = ' '.join([line['text'] for line in transcript])
|
@@ -151,6 +139,10 @@ def main():
|
|
151 |
st.write(f"Polarity: {sentiment.polarity}")
|
152 |
st.write(f"Subjectivity: {sentiment.subjectivity}")
|
153 |
|
|
|
|
|
|
|
|
|
154 |
except Exception as e:
|
155 |
st.error(f"Error: {str(e)}")
|
156 |
|
|
|
10 |
import re
|
11 |
import nltk
|
12 |
|
13 |
+
# Ensure necessary NLTK data is downloaded
|
14 |
nltk.download('punkt')
|
15 |
nltk.download('stopwords')
|
16 |
nltk.download('wordnet')
|
17 |
+
nltk.download('tokenizers/punkt_tab/english') # Added to resolve punkt_tab error
|
18 |
|
19 |
# Function to summarize text
|
20 |
def summarize_text(text, max_length=80000): # Increased max_length to 80,000
|
21 |
+
summarization_pipeline = pipeline("summarization")
|
22 |
summary = summarization_pipeline(text, max_length=max_length, min_length=100, do_sample=False)
|
23 |
return summary[0]['summary_text']
|
24 |
|
|
|
64 |
break
|
65 |
return video_id
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
# Main Streamlit app
|
68 |
def main():
|
69 |
st.title("YouTube Video Summarizer")
|
|
|
105 |
return
|
106 |
|
107 |
# Get transcript of the video
|
108 |
+
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
109 |
if not transcript:
|
110 |
+
st.error("Transcript not available for this video. Please try a different video.")
|
111 |
return
|
112 |
|
113 |
video_text = ' '.join([line['text'] for line in transcript])
|
|
|
139 |
st.write(f"Polarity: {sentiment.polarity}")
|
140 |
st.write(f"Subjectivity: {sentiment.subjectivity}")
|
141 |
|
142 |
+
except TranscriptsDisabled:
|
143 |
+
st.error("Transcripts are disabled for this video. Please try a different video.")
|
144 |
+
except NoTranscriptFound:
|
145 |
+
st.error("No transcript found for this video. Please try a different video.")
|
146 |
except Exception as e:
|
147 |
st.error(f"Error: {str(e)}")
|
148 |
|