diff --git a/README.md b/README.md index cc5560e..c123c1d 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,13 @@ Run the following to view all available options: yt_whisper --help + +## Similar Work +A streamlit based webapp using yt-whisper for capturing and downloading subtitles from youtube videos as per the user's input : https://github.com/prateekralhan/Youtube-Whisper-Streamlit + +![](https://user-images.githubusercontent.com/29462447/201472171-0c20444c-82a4-444e-85eb-a1898c9ae896.gif) + + ## License This script is open-source and licensed under the MIT License. For more details, check the [LICENSE](LICENSE) file. diff --git a/streamlit_app/Aptfile b/streamlit_app/Aptfile new file mode 100644 index 0000000..a9f1eea --- /dev/null +++ b/streamlit_app/Aptfile @@ -0,0 +1 @@ +ffmpeg \ No newline at end of file diff --git a/streamlit_app/Dockerfile b/streamlit_app/Dockerfile new file mode 100644 index 0000000..da7e8ed --- /dev/null +++ b/streamlit_app/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.7 + +RUN pip install virtualenv +ENV VIRTUAL_ENV=/venv +RUN virtualenv venv -p python3 +ENV PATH="VIRTUAL_ENV/bin:$PATH" + +WORKDIR /app +ADD . /app + +# Install dependencies +RUN pip install -r requirements.txt +RUN apt-get update +RUN apt-get install ffmpeg + +# Expose port +ENV PORT 8501 + +# Run the application: +CMD ["streamlit","run","app.py"] \ No newline at end of file diff --git a/streamlit_app/Procfile b/streamlit_app/Procfile new file mode 100644 index 0000000..645733f --- /dev/null +++ b/streamlit_app/Procfile @@ -0,0 +1 @@ +web: sh setup.sh && streamlit run app.py \ No newline at end of file diff --git a/streamlit_app/app.py b/streamlit_app/app.py new file mode 100644 index 0000000..d6a686d --- /dev/null +++ b/streamlit_app/app.py @@ -0,0 +1,74 @@ +import os +import subprocess +import glob +import shutil +import streamlit as st +from PIL import Image +from whisper.tokenizer import LANGUAGES + +@st.cache(persist=True,allow_output_mutation=False,show_spinner=True,suppress_st_warning=True) +def clean_directory(dirpath): + for filename in os.listdir(dirpath): + filepath = os.path.abspath(os.path.join(dirpath, filename)) + try: + shutil.rmtree(filepath) + except OSError: + os.remove(filepath) + +st.set_page_config( + page_title="Youtube - Whisper", + page_icon="🎶", + layout="centered", + initial_sidebar_state="auto", +) + +main_image = Image.open('static/main_banner.png') + +download_path = "output/" +clean_directory(download_path) + +st.image(main_image,use_column_width='auto') +st.title("✨ Automatic YouTube subtitle generation 🔊") +st.error(" 🔴 THIS IS MEANT TO BE USED FOR EDUCATIONAL PURPOSES ONLY!! 🔴") +st.info('⚠ Fetching the YouTube video and it\'s subtitles generation may take several minutes depending on the time duration, size and your choices 😉') + +col1, col2, col3, col4 = st.columns(4) +with col1: + model_type = st.radio("Please choose your model type", ('Tiny', 'Base', 'Small', 'Medium', 'Large')) +with col2: + format_type = st.radio("Please choose your output format type", ('VTT', 'SRT')) +with col3: + task_type = st.radio("Please choose your task type", ('Transcribe', 'Translate')) +with col4: + language = st.selectbox('Please select the language',tuple(LANGUAGES.values())) + +url = st.text_input("Enter your YouTube Video URL: 🔗") +if url is not None or url != '': + if st.button("Fetch Video and Generate Subtitles 🚀"): + st.video(url.strip()) + with st.spinner("Working... 💫 Meanwhile please enjoy your video 😉"): + subprocess.run(["yt_whisper", url, "--model", model_type.lower(), "--format", format_type.lower(), "--output_dir", "output", "--verbose", "True", "--task", task_type.lower(), "--language", language.title()]) + + filename = glob.glob("output/*")[0] + output_file = open(filename,"r") + output_file_data = output_file.read() + + if filename.endswith(".srt"): + mime_type = "text/plain" + else: + mime_type = "text/vtt" + + if st.download_button( + label="Download Subtitles 📝", + data=output_file_data, + file_name=filename, + mime=mime_type + ): + st.balloons() + st.success('✅ Download Successful !!') + +else: + st.warning('⚠ Please enter the URL! 😯') + + +st.markdown("

Made with ❤️ by Prateek Ralhan with the help of [yt-whisper](https://github.com/m1guelpf/yt-whisper) built by [m1guelpf](https://github.com/m1guelpf) ✨

", unsafe_allow_html=True) diff --git a/streamlit_app/demo.gif b/streamlit_app/demo.gif new file mode 100644 index 0000000..8ad75a8 Binary files /dev/null and b/streamlit_app/demo.gif differ diff --git a/streamlit_app/output/Rick_Astley___Never_Gonna_Give_You_Up__Official_Music_Video.vtt b/streamlit_app/output/Rick_Astley___Never_Gonna_Give_You_Up__Official_Music_Video.vtt new file mode 100644 index 0000000..a9b1a7a --- /dev/null +++ b/streamlit_app/output/Rick_Astley___Never_Gonna_Give_You_Up__Official_Music_Video.vtt @@ -0,0 +1,206 @@ +WEBVTT + +00:00.000 --> 00:20.520 +Youth + +00:20.520 --> 00:26.520 +You know the rules and so do I + +00:26.520 --> 00:30.520 +I've broken it means far I'm deep in love + +00:30.520 --> 00:34.520 +You won't get this wrong any other guy + +00:34.520 --> 00:39.520 +I just wanna tell you how I'm feeling + +00:39.520 --> 00:42.520 +Gotta make you understand + +00:42.520 --> 00:44.520 +Never gonna give you home + +00:44.520 --> 00:46.520 +Never gonna let you down + +00:46.520 --> 00:50.520 +Never gonna run around and you just do + +00:50.520 --> 00:53.520 +Never gonna make you cry + +00:53.520 --> 00:55.520 +Never gonna shake you back + +00:55.520 --> 00:57.520 +Never gonna jay on the mind + +00:57.520 --> 00:59.520 +And hurt you + +00:59.520 --> 01:04.520 +We know each other for so long + +01:04.520 --> 01:06.520 +You'll start to be naked now + +01:06.520 --> 01:08.520 +You'll just start to say + +01:08.520 --> 01:10.520 +If you stop being focused + +01:10.520 --> 01:12.520 +We'll go alone + +01:12.520 --> 01:15.520 +We know the game I'm wearing + +01:15.520 --> 01:21.520 +Gotta play it and you do I speak how I'm feeling + +01:21.520 --> 01:23.520 +Don't tell me or two + +01:23.520 --> 01:24.520 +But you see + +01:24.520 --> 01:26.520 +Never gonna give you home + +01:26.520 --> 01:28.520 +Never gonna let you down + +01:28.520 --> 01:32.520 +Never gonna run around and you just do + +01:32.520 --> 01:35.520 +Never gonna make you cry + +01:35.520 --> 01:37.520 +Never gonna shake you back + +01:37.520 --> 01:39.520 +Never gonna jay on the mind + +01:39.520 --> 01:41.520 +And hurt you + +01:41.520 --> 01:43.520 +Never gonna give you home + +01:43.520 --> 01:46.520 +Never gonna let you down + +01:46.520 --> 01:50.520 +Never gonna run around and you just do + +01:50.520 --> 01:52.520 +Never gonna make you cry + +01:52.520 --> 01:54.520 +Never gonna shake you back + +01:54.520 --> 01:56.520 +Never gonna jay on the mind + +01:56.520 --> 01:59.520 +And hurt you + +01:59.520 --> 02:02.520 +Never gonna give you home + +02:02.520 --> 02:07.520 +Never gonna give you home + +02:07.520 --> 02:12.520 +Never gonna give you home + +02:12.520 --> 02:14.520 +Never gonna give me, never gonna give me + +02:14.520 --> 02:16.520 +In my life + +02:16.520 --> 02:20.520 +We've known each other for so long + +02:20.520 --> 02:22.520 +Your husband ain't king of + +02:22.520 --> 02:24.520 +Your just has to say + +02:24.520 --> 02:26.520 +It's a surprise for the husband + +02:26.520 --> 02:28.520 +Go on, on + +02:28.520 --> 02:32.520 +We know the game and we're gonna play it + +02:32.520 --> 02:37.520 +I just wanna tell you how I feel it + +02:37.520 --> 02:40.520 +Gotta make you understand + +02:40.520 --> 02:42.520 +Never gonna give you, or + +02:42.520 --> 02:44.520 +We've known each other for so long + +02:44.520 --> 02:46.520 +Your husband ain't king of + +02:46.520 --> 02:48.520 +Your just has to say + +02:48.520 --> 02:50.520 +It's a surprise for the husband + +02:50.520 --> 02:53.520 +Go on, on we're gonna save the + +02:53.520 --> 02:56.520 +Bad, no, no, no, no + +02:56.520 --> 02:58.520 +And bad too + +02:58.520 --> 03:00.520 +Never gonna give you, or + +03:00.520 --> 03:02.520 +We've known each other for so long + +03:02.520 --> 03:04.520 +We've known each other for so long + +03:04.520 --> 03:06.520 +We've known each other for so long + +03:06.520 --> 03:10.520 +Your husband ain't king of + +03:10.520 --> 03:12.520 +Your just has to say + +03:12.520 --> 03:14.520 +It's a surprise for the husband + +03:14.520 --> 03:16.520 +Go on, on we're gonna give you, or + +03:16.520 --> 03:20.520 +We've known each other for so long + +03:20.520 --> 03:22.520 +Your husband ain't king of + +03:22.520 --> 03:26.520 +Your just has to say + diff --git a/streamlit_app/requirements.txt b/streamlit_app/requirements.txt new file mode 100644 index 0000000..075e455 Binary files /dev/null and b/streamlit_app/requirements.txt differ diff --git a/streamlit_app/runtime.txt b/streamlit_app/runtime.txt new file mode 100644 index 0000000..a81f85c --- /dev/null +++ b/streamlit_app/runtime.txt @@ -0,0 +1 @@ +python-3.7.13 \ No newline at end of file diff --git a/streamlit_app/setup.sh b/streamlit_app/setup.sh new file mode 100644 index 0000000..43a5fc5 --- /dev/null +++ b/streamlit_app/setup.sh @@ -0,0 +1,9 @@ +mkdir -p ~/.streamlit/ +echo "[general] +email = \"ralhanprateek@gmail.com\" +" > ~/.streamlit/credentials.toml +echo "[server] +headless = true +port = $PORT +enableCORS = false +" > ~/.streamlit/config.toml \ No newline at end of file diff --git a/streamlit_app/static/main_banner.png b/streamlit_app/static/main_banner.png new file mode 100644 index 0000000..3793f35 Binary files /dev/null and b/streamlit_app/static/main_banner.png differ