import whisper from pytube import YouTube from transformers import pipeline import gradio as gr import os import re # model = whisper.load_model("base") # model = pipeline(model="AlexMo/FIFA_WC22_WINNER_LANGUAGE_MODEL") model = pipeline(model="AlexMo/improved_whisper_model") summarizer = pipeline("summarization") def transcribe_inp(microphone, file_upload): warn_output = "" if (microphone is not None) and (file_upload is not None): warn_output = ( "NOTE: The audio file will be discarded after this run.\n" ) elif (microphone is None) and (file_upload is None): return "ERROR: You have to either use the microphone or upload an audio file" file = microphone if microphone is not None else file_upload text = model(file, batch_size=1024)["text"] return warn_output + text def getAudio(url): link = YouTube(url) video = link.streams.filter(only_audio=True).first() file = video.download(output_path=".") base, ext = os.path.splitext(file) file_ext = base + '.mp3' os.rename(file, file_ext) return file_ext def getText(url): if url != '': output_text_transcribe = '' res = model(getAudio(url)) return res['text'].strip() def getSummary(article): # header = ' '.join(re.split(r'(?<=[.:;])\s', article)[:5]) b = summarizer(article, min_length=15, max_length=120, do_sample=False) b = b[0]['summary_text'].replace(' .', '.').strip() return b with gr.Blocks() as demo: gr.HTML( """
Summarize audio files, mic input or Youtube videos using OpenAI's Whisper