Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import yt_dlp as youtube_dl
|
3 |
import os
|
4 |
-
import random
|
5 |
|
6 |
def download_youtube_video(url: str, file_name: str) -> str:
|
7 |
ydl_opts = {
|
@@ -17,56 +17,35 @@ def download_youtube_video(url: str, file_name: str) -> str:
|
|
17 |
ydl.download([url])
|
18 |
return f"{file_name}.mp3"
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
23 |
|
24 |
-
|
25 |
-
if not st.session_state.captcha_solved:
|
26 |
-
num1 = random.randint(1, 10)
|
27 |
-
num2 = random.randint(1, 10)
|
28 |
-
captcha_result = num1 + num2
|
29 |
-
st.session_state.captcha_answer = captcha_result
|
30 |
-
|
31 |
-
st.title("YouTube Audio Downloader")
|
32 |
|
33 |
url = st.text_input("Enter YouTube URL:")
|
34 |
|
35 |
-
|
36 |
-
if
|
37 |
-
|
38 |
-
if st.button("Verify CAPTCHA"):
|
39 |
try:
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
else:
|
44 |
-
st.error("
|
45 |
-
except
|
46 |
-
st.error("
|
|
|
|
|
47 |
|
48 |
-
# Allow downloading if CAPTCHA has been solved
|
49 |
-
if st.session_state.captcha_solved:
|
50 |
-
if st.button("Download Audio"):
|
51 |
-
if url:
|
52 |
-
st.write("Downloading audio...")
|
53 |
-
try:
|
54 |
-
audio_file = download_youtube_video(url, "audio")
|
55 |
-
st.write("Audio downloaded successfully.")
|
56 |
|
57 |
-
if os.path.exists(audio_file):
|
58 |
-
with open(audio_file, "rb") as file:
|
59 |
-
st.download_button(
|
60 |
-
label="Download Audio",
|
61 |
-
data=file,
|
62 |
-
file_name="audio.mp3",
|
63 |
-
mime="audio/mpeg"
|
64 |
-
)
|
65 |
-
else:
|
66 |
-
st.error("Audio file was not saved correctly.")
|
67 |
-
except youtube_dl.utils.DownloadError as e:
|
68 |
-
st.error("An error occurred while downloading the audio: The video might require additional authentication (e.g., YouTube login).")
|
69 |
-
except Exception as e:
|
70 |
-
st.error(f"An unexpected error occurred: {e}")
|
71 |
-
else:
|
72 |
-
st.error("Please enter a valid YouTube URL.")
|
|
|
1 |
import streamlit as st
|
2 |
+
from faster_whisper import WhisperModel
|
3 |
import yt_dlp as youtube_dl
|
4 |
import os
|
|
|
5 |
|
6 |
def download_youtube_video(url: str, file_name: str) -> str:
|
7 |
ydl_opts = {
|
|
|
17 |
ydl.download([url])
|
18 |
return f"{file_name}.mp3"
|
19 |
|
20 |
+
def transcribe_audio(file_name: str):
|
21 |
+
model = WhisperModel("medium", device="cpu", compute_type="float32")
|
22 |
+
segments, _ = model.transcribe(file_name)
|
23 |
+
return ''.join([segment.text for segment in segments])
|
24 |
|
25 |
+
st.title("YouTube Video Transcription with Whisper")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
url = st.text_input("Enter YouTube URL:")
|
28 |
|
29 |
+
if st.button("Download Audio"):
|
30 |
+
if url:
|
31 |
+
st.write("Downloading audio...")
|
|
|
32 |
try:
|
33 |
+
audio_file = download_youtube_video(url, "podcast_audio")
|
34 |
+
st.write("Audio downloaded successfully.")
|
35 |
+
|
36 |
+
if os.path.exists(audio_file):
|
37 |
+
with open(audio_file, "rb") as file:
|
38 |
+
st.download_button(
|
39 |
+
label="Download Audio",
|
40 |
+
data=file,
|
41 |
+
file_name="audio.mp3",
|
42 |
+
mime="audio/mpeg"
|
43 |
+
)
|
44 |
else:
|
45 |
+
st.error("Audio file was not saved correctly.")
|
46 |
+
except Exception as e:
|
47 |
+
st.error(f"An error occurred: {e}")
|
48 |
+
else:
|
49 |
+
st.error("Please enter a valid YouTube URL.")
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|