Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +36 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from faster_whisper import WhisperModel
|
3 |
+
import yt_dlp as youtube_dl
|
4 |
+
|
5 |
+
def download_youtube_video(url: str, file_name: str) -> str:
|
6 |
+
ydl_opts = {
|
7 |
+
'format': 'bestaudio/best',
|
8 |
+
'outtmpl': f'{file_name}.%(ext)s',
|
9 |
+
'postprocessors': [{
|
10 |
+
'key': 'FFmpegExtractAudio',
|
11 |
+
'preferredcodec': 'mp3',
|
12 |
+
'preferredquality': '192',
|
13 |
+
}],
|
14 |
+
}
|
15 |
+
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
16 |
+
ydl.download([url])
|
17 |
+
return f"{file_name}.mp3"
|
18 |
+
|
19 |
+
def transcribe_audio(file_name: str):
|
20 |
+
model = WhisperModel("large-v2", device="cpu", compute_type="float32")
|
21 |
+
segments, _ = model.transcribe(file_name)
|
22 |
+
return ''.join([segment.text for segment in segments])
|
23 |
+
|
24 |
+
st.title("YouTube Video Transcription with Whisper")
|
25 |
+
|
26 |
+
url = st.text_input("Enter YouTube URL:")
|
27 |
+
if st.button("Download and Transcribe"):
|
28 |
+
if url:
|
29 |
+
st.write("Downloading audio...")
|
30 |
+
audio_file = download_youtube_video(url, "podcast_audio")
|
31 |
+
st.write("Transcribing audio...")
|
32 |
+
transcription = transcribe_audio(audio_file)
|
33 |
+
st.write("Transcription:")
|
34 |
+
st.write(transcription)
|
35 |
+
else:
|
36 |
+
st.error("Please enter a valid YouTube URL.")
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
faster-whisper==1.0.3
|
2 |
+
streamlit==1.24.1
|
3 |
+
yt-dlp==2024.8.1
|
4 |
+
pydub==0.25.1
|