Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import whisper
|
2 |
+
import yt_dlp
|
3 |
+
import gradio as gr
|
4 |
+
import os
|
5 |
+
import re
|
6 |
+
import logging
|
7 |
+
|
8 |
+
logging.basicConfig(level=logging.INFO)
|
9 |
+
model = whisper.load_model("medium")
|
10 |
+
def get_text(url):
|
11 |
+
#try:
|
12 |
+
if url != '':
|
13 |
+
output_text_transcribe = ''
|
14 |
+
|
15 |
+
with yt_dlp.YoutubeDL({'format': 'bestaudio', 'audio-format': 'wav', 'outtmpl': '%(id)s.%(ext)s'}) as ydl:
|
16 |
+
# Extract information from the given YouTube URL and download the best audio format available
|
17 |
+
info_dict = ydl.extract_info(url, download=True)
|
18 |
+
# Prepare the filename of the downloaded audio file
|
19 |
+
audio_file = ydl.prepare_filename(info_dict) #finally:
|
20 |
+
# raise gr.Error("Exception: There was a problem transcribing the audio.")
|
21 |
+
result = model.transcribe(audio_file, task="transcribe")
|
22 |
+
return result['text'].strip()
|
23 |
+
|
24 |
+
with gr.Blocks() as demo:
|
25 |
+
gr.Markdown("<h1><center>YouTube Video-to-Text using Whisper</center></h1>")
|
26 |
+
gr.Markdown("<center>Enter the link of any YouTube video to generate a text transcript of the video.</center>")
|
27 |
+
|
28 |
+
input_text_url = gr.Textbox(placeholder='Youtube video URL', label='YouTube URL')
|
29 |
+
result_button_transcribe = gr.Button('Transcribe')
|
30 |
+
output_text_transcribe = gr.Textbox(placeholder='Transcript of the YouTube video.', label='Transcript')
|
31 |
+
|
32 |
+
result_button_transcribe.click(get_text, inputs = input_text_url, outputs = output_text_transcribe)
|
33 |
+
demo.queue(default_enabled = True).launch(debug = True)
|