import gradio as gr from youtube_transcript_api import YouTubeTranscriptApi def get_transcript(youtube_url): try: # Extract the video ID from the YouTube URL video_id = youtube_url.split("?v=")[1] # Get the transcript transcript = YouTubeTranscriptApi.get_transcript(video_id) transcript_text = " ".join([entry["text"] for entry in transcript]) return transcript_text except Exception as e: return f"Error: {str(e)}" interface = gr.Interface( fn=get_transcript, inputs=gr.components.Textbox(label="Enter YouTube URL"), outputs=gr.components.Textbox(label="Transcript"), title="YouTube Transcript Extractor", description="Enter a YouTube URL to extract the transcript of the video.", ) if __name__ == "__main__": interface.launch()