ccxccc
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,20 @@
|
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
from youtube_transcript_api import YouTubeTranscriptApi
|
3 |
import streamlit as st
|
4 |
import re
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def summarize(result):
|
7 |
summarizer = pipeline('summarization')
|
8 |
num_iters = int(len(result)/1000)
|
@@ -19,6 +31,14 @@ def summarize(result):
|
|
19 |
summarized_text.append(out)
|
20 |
st.write(summarized_text)
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
def get_transcript(video_link):
|
23 |
video_id = extract_video_id(video_link)
|
24 |
if video_id:
|
@@ -28,21 +48,17 @@ def get_transcript(video_link):
|
|
28 |
result += ' ' + i['text']
|
29 |
print(len(result))
|
30 |
st.write(result)
|
31 |
-
# If you want to summarize the transcript
|
32 |
summarize(result)
|
33 |
else:
|
34 |
st.write("Invalid YouTube video link")
|
35 |
|
36 |
-
def extract_video_id(video_link):
|
37 |
-
# Regular expression to extract video ID from YouTube video link
|
38 |
-
regex = r"(?:https:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})"
|
39 |
-
matches = re.findall(regex, video_link)
|
40 |
-
if matches:
|
41 |
-
return matches[0]
|
42 |
-
else:
|
43 |
-
return None
|
44 |
-
|
45 |
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
video_link = st.text_input("Enter YouTube video link:")
|
47 |
if video_link:
|
48 |
get_transcript(video_link)
|
|
|
1 |
+
import subprocess
|
2 |
+
import importlib.util
|
3 |
from transformers import pipeline
|
4 |
from youtube_transcript_api import YouTubeTranscriptApi
|
5 |
import streamlit as st
|
6 |
import re
|
7 |
|
8 |
+
def check_installation(package):
|
9 |
+
spec = importlib.util.find_spec(package)
|
10 |
+
if spec is None:
|
11 |
+
return False
|
12 |
+
else:
|
13 |
+
return True
|
14 |
+
|
15 |
+
def install_tensorflow():
|
16 |
+
subprocess.check_call(['pip', 'install', 'tensorflow==2.0'])
|
17 |
+
|
18 |
def summarize(result):
|
19 |
summarizer = pipeline('summarization')
|
20 |
num_iters = int(len(result)/1000)
|
|
|
31 |
summarized_text.append(out)
|
32 |
st.write(summarized_text)
|
33 |
|
34 |
+
def extract_video_id(video_link):
|
35 |
+
regex = r"(?:https:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})"
|
36 |
+
matches = re.findall(regex, video_link)
|
37 |
+
if matches:
|
38 |
+
return matches[0]
|
39 |
+
else:
|
40 |
+
return None
|
41 |
+
|
42 |
def get_transcript(video_link):
|
43 |
video_id = extract_video_id(video_link)
|
44 |
if video_id:
|
|
|
48 |
result += ' ' + i['text']
|
49 |
print(len(result))
|
50 |
st.write(result)
|
|
|
51 |
summarize(result)
|
52 |
else:
|
53 |
st.write("Invalid YouTube video link")
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
def main():
|
56 |
+
if not check_installation("tensorflow"):
|
57 |
+
st.write("TensorFlow 2.0 is not installed. Installing...")
|
58 |
+
install_tensorflow()
|
59 |
+
|
60 |
+
import tensorflow as tf
|
61 |
+
|
62 |
video_link = st.text_input("Enter YouTube video link:")
|
63 |
if video_link:
|
64 |
get_transcript(video_link)
|