import whisper from pytube import YouTube #from transformers import pipeline import gradio as gr import os import re model = whisper.load_model("base") #summarizer = pipeline("summarization") #def get_audio(url): #try: #yt = YouTube(url) #if yt.length < 5400: #video = yt.streams.filter(only_audio=True).first() #out_file=video.download(output_path=".") #base, ext = os.path.splitext(out_file) #new_file = base+'.mp3' #os.rename(out_file, new_file) #a = new_file #return a #else: #raise gr.Error("Videos for transcription on this space are limited to 1.5 hours. Sorry about this limit but some joker thought they could stop this tool from working by transcribing many extremely long videos.") #return "" #finally: #raise gr.Error("Exception: There was a problem getting the video or audio of the URL provided.") def get_text(url): #try: if url != '': output_text_transcribe = '' yt = YouTube(url) if yt.length < 5400: video = yt.streams.filter(only_audio=True).first() out_file=video.download(output_path=".") 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: return "Videos for transcription on this space are limited to 1.5 hours. Sorry about this limit but some joker thought they could stop this tool from working by transcribing many extremely long videos. Please visit https://steve.digital to contact me about this space." #finally: #raise gr.Error("Exception: There was a problem transcribing the audio after successfully retrieving it from the video/URL.") def get_summary(article): #try: 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 #finally: #raise gr.Error("Exception: There was a problem summarizing the transcript.") with gr.Blocks() as demo: gr.Markdown("