Spaces:
Runtime error
Runtime error
File size: 2,563 Bytes
bc736f8 97fd8dc bc736f8 b640e62 49d7053 bc736f8 49d7053 a63bdf7 bc736f8 9ec122f e3b3ac8 9ec122f 9e07c40 54e9c4b 4a71c2c e3b3ac8 9e07c40 e3b3ac8 c93db71 9ec122f bc736f8 896fad4 5188c19 bc736f8 c93db71 fe55d4b c93db71 5188c19 4a71c2c 5188c19 fe55d4b 5188c19 fe55d4b 5188c19 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import whisper
from pytube import YouTube
import gradio as gr
import os
import re
import logging
logging.basicConfig(level=logging.INFO)
model = whisper.load_model("base")
def get_text(url):
#try:
if url != '':
output_text_transcribe = ''
yt = YouTube(url)
#video_length = yt.length --- doesn't work anymore - using byte file size of the audio file instead now
#if video_length < 5400:
video = yt.streams.filter(only_audio=True).first()
out_file=video.download(output_path=".")
file_stats = os.stat(out_file)
logging.info(f'Size of audio file in Bytes: {file_stats.st_size}')
if file_stats.st_size <= 30000000:
base, ext = os.path.splitext(out_file)
new_file = base+'.mp3'
os.rename(out_file, new_file)
a = new_file
result = model.transcribe(a)
return result['text'].strip()
else:
logging.error('Videos for transcription on this demo are limited to about 1.5 hours.')
#finally:
# raise gr.Error("Exception: There was a problem transcribing the audio.")
def get_summary(article):
first_sentences = ' '.join(re.split(r'(?<=[.:;])\s', article)[:5])
b = summarizer(first_sentences, min_length = 20, max_length = 120, do_sample = False)
b = b[0]['summary_text'].replace(' .', '.').strip()
return b
with gr.Blocks() as demo:
gr.Markdown("<h1><center>Free Fast YouTube URL Video-to-Text")
#gr.Markdown("<center>Enter the link of any YouTube video to generate a text transcript of the video and then create a summary of the video transcript.</center>")
gr.Markdown("<center>Enter the link of any YouTube video to generate a text transcript of the video.</center>")
gr.Markdown("<center>Transcription takes 5-10 seconds per minute of the video (bad audio/hard accents slow it down a bit).</center>")
input_text_url = gr.Textbox(placeholder='Youtube video URL', label='YouTube URL')
result_button_transcribe = gr.Button('Transcribe')
output_text_transcribe = gr.Textbox(placeholder='Transcript of the YouTube video.', label='Transcript')
#result_button_summary = gr.Button('2. Create Summary')
#output_text_summary = gr.Textbox(placeholder='Summary of the YouTube video transcript.', label='Summary')
result_button_transcribe.click(get_text, inputs = input_text_url, outputs = output_text_transcribe)
#result_button_summary.click(get_summary, inputs = output_text_transcribe, outputs = output_text_summary)
demo.queue(default_enabled = True).launch(debug = True) |