hadxu commited on
Commit
9d79ca0
1 Parent(s): f1a61b0
Files changed (2) hide show
  1. app.py +78 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from pytube import YouTube
3
+ import yt_dlp
4
+
5
+
6
+ # from faster_whisper import WhisperModel
7
+ # model = WhisperModel("large-v2", device="cpu", device_index=0, compute_type="float16")
8
+
9
+ DESCRIPTION = """
10
+ Welcome to the **YouTube Video summary** powered by Llama-2 models.
11
+ """
12
+ st.title("YouTube Video summary")
13
+ st.markdown(DESCRIPTION)
14
+
15
+ def get_video_title(youtube_url: str) -> str:
16
+ yt = YouTube(youtube_url)
17
+ embed_url = f"https://www.youtube.com/embed/{yt.video_id}"
18
+ embed_html = f'<iframe src="{embed_url}" frameborder="0" allowfullscreen></iframe>'
19
+ return yt.title, embed_html
20
+
21
+
22
+ def initialize_session_state():
23
+ if "youtube_url" not in st.session_state:
24
+ st.session_state.youtube_url = ""
25
+ if "model_choice" not in st.session_state:
26
+ st.session_state.model_choice = "Llama2-70b"
27
+ if "setup_done" not in st.session_state:
28
+ st.session_state.setup_done = False
29
+ if "doneYoutubeurl" not in st.session_state:
30
+ st.session_state.doneYoutubeurl = ""
31
+
32
+ def sidebar():
33
+ with st.sidebar:
34
+ st.markdown("Enter the YouTube Video URL below🔗")
35
+ st.session_state.youtube_url = st.text_input("YouTube Video URL:")
36
+
37
+ if st.session_state.youtube_url:
38
+ # Get the video title
39
+ video_title, embed_html = get_video_title(st.session_state.youtube_url)
40
+ st.markdown(f"### {video_title}")
41
+
42
+ # Embed the video
43
+ st.markdown(embed_html, unsafe_allow_html=True)
44
+
45
+ sidebar()
46
+ initialize_session_state()
47
+
48
+ ydl_opts = {
49
+ 'outtmpl': 'demo.m4a',
50
+ 'format': 'm4a/bestaudio/best',
51
+ # ℹ️ See help(yt_dlp.postprocessor) for a list of available Postprocessors and their arguments
52
+ 'postprocessors': [{ # Extract audio using ffmpeg
53
+ 'key': 'FFmpegExtractAudio',
54
+ 'preferredcodec': 'm4a',
55
+ }],
56
+ }
57
+
58
+ if st.session_state.youtube_url:
59
+ with st.status("Get video Audio..."):
60
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
61
+ error_code = ydl.download([st.session_state.youtube_url])
62
+
63
+ audio_file = open('demo.m4a', 'rb')
64
+ audio_bytes = audio_file.read()
65
+ st.audio(audio_bytes, format='audio/ogg')
66
+
67
+
68
+ # segments, info = model.transcribe("demo.m4a", beam_size=5)
69
+ # st.markdown("Detected language '%s' with probability %f" % (info.language, info.language_probability))
70
+
71
+ # full_response = ""
72
+ # message_placeholder = st.empty()
73
+ # for segment in segments:
74
+ # # print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
75
+ # full_response += segment.text + " "
76
+ # st.write(segment.text)
77
+ # message_placeholder.markdown(full_response + "▌")
78
+ # message_placeholder.markdown(full_response)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ pytube
2
+ yt_dlp