import os import whisper import gradio as gr from download_video import download_mp3_yt_dlp import warnings warnings.filterwarnings("ignore", category=FutureWarning, module="torch") # Function to download the audio, title, and thumbnail from YouTube def download_video_info(url): try: # Call the function to download video and get title, thumbnail title, thumbnail_url = download_mp3_yt_dlp(url) audio_file = "downloaded_video.mp3" # Path to the downloaded audio (MP3) return audio_file, title, thumbnail_url except Exception as e: return None, None, None, str(e) # Function to transcribe the downloaded audio using Whisper def transcribe_audio(audio_path, model_size="base", language="en"): model = whisper.load_model(model_size) result = model.transcribe(audio_path, language=language) return result['text'] # Split logic: First fetch title and thumbnail, then transcribe def get_video_info_and_transcribe(youtube_url, model_size="base", language="en"): # Fetch title and thumbnail first audio_path, title, thumbnail_url = download_video_info(youtube_url) # If fetching video info fails if not audio_path or not os.path.exists(audio_path): return gr.update(value="Error fetching video."), None, None # Show title and thumbnail to the user while the transcription is happening title_output = gr.update(value=title) # Show the thumbnail if available if thumbnail_url: thumbnail_output = gr.update(value=thumbnail_url) else: thumbnail_output = gr.update(visible=False) # Hide if no thumbnail # Start transcription transcription = transcribe_audio(audio_path, model_size, language) return title_output, thumbnail_output, gr.update(value=transcription) # Gradio interface setup using gradio.components with gr.Blocks() as demo: title = "