import os os.system("python -m pip install --upgrade pip") os.system("pip install git+https://github.com/openai/whisper.git") os.system("pip install pytube") import whisper from pytube import YouTube import gradio as gr import os import re model = whisper.load_model("base") # def compress_audio(file_path, bitrate='32k'): # try: # audio = AudioSegment.from_file(file_path) # output_format = os.path.splitext(file_path)[1][1:] # compressed_audio = audio.export(file_path, format=output_format, bitrate=bitrate) # return True # except Exception as e: # print(f"Error: {e}") # return False def url_to_text(url): if url != '': output_text_transcribe = '' yt = YouTube(url) video = yt.streams.filter(only_audio=True).first() out_file=video.download(output_path=".") file_stats = os.stat(out_file) if file_stats.st_size <= 30_000_000: base, ext = os.path.splitext(out_file) os.rename(out_file, base+'.mp3') file_path = base+'.mp3' # compress_audio(file_path) result = model.transcribe(file_path) return result['text'].strip() else: raise gr.Error("Exception: Problems with the audio transcription.") 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("