Spaces:
Paused
Paused
Ayushnangia
commited on
Commit
•
29685bd
1
Parent(s):
d0775b4
adding the transcriber downloader code
Browse files- app.py +52 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import yt_dlp as ydlp
|
3 |
+
from whispercpp import Whisper
|
4 |
+
|
5 |
+
def download_audio(youtube_url, output_folder='.'):
|
6 |
+
ydl_opts = {
|
7 |
+
'format': 'bestaudio/best',
|
8 |
+
'postprocessors': [{
|
9 |
+
'key': 'FFmpegExtractAudio',
|
10 |
+
'preferredcodec': 'wav',
|
11 |
+
'preferredquality': '192',
|
12 |
+
}],
|
13 |
+
'outtmpl': f'{output_folder}/audio',
|
14 |
+
}
|
15 |
+
|
16 |
+
with ydlp.YoutubeDL(ydl_opts) as ydl:
|
17 |
+
ydl.download([youtube_url])
|
18 |
+
|
19 |
+
|
20 |
+
w = Whisper('tiny')
|
21 |
+
|
22 |
+
|
23 |
+
def process_general_transcription(transcription):
|
24 |
+
formatted_transcription = []
|
25 |
+
|
26 |
+
for line in transcription:
|
27 |
+
if line.startswith('[') and line.endswith(']'):
|
28 |
+
formatted_transcription.append(f'\n--- {line[1:-1].upper()} ---\n')
|
29 |
+
else:
|
30 |
+
formatted_transcription.append(line)
|
31 |
+
|
32 |
+
transcript_str = "\n".join(formatted_transcription)
|
33 |
+
|
34 |
+
return transcript_str
|
35 |
+
def transcribe_youtube(youtube_url):
|
36 |
+
download_audio(youtube_url)
|
37 |
+
result = w.transcribe("audio.wav")
|
38 |
+
text = w.extract_text(result)
|
39 |
+
return process_general_transcription(text)
|
40 |
+
with gr.Blocks() as demo:
|
41 |
+
gr.Markdown(
|
42 |
+
"""
|
43 |
+
# CPP Whisperer - Transcribe YouTube Videos
|
44 |
+
|
45 |
+
""")
|
46 |
+
inp = gr.Textbox(placeholder="Insert YT Url here")
|
47 |
+
result_button_transcribe = gr.Button('Transcribe')
|
48 |
+
out = gr.Textbox()
|
49 |
+
result_button_transcribe.click(transcribe_youtube, inputs = inp, outputs = out)
|
50 |
+
|
51 |
+
|
52 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
git+https://github.com/stlukey/whispercpp.py
|
2 |
+
gradio
|
3 |
+
yt_dlp
|