Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| def convert_to_embed_url(youtube_url): | |
| if "youtube.com/watch?v=" in youtube_url: | |
| video_id = youtube_url.split("v=")[1].split("&")[0] | |
| elif "youtu.be/" in youtube_url: | |
| video_id = youtube_url.split("youtu.be/")[1].split("?")[0] | |
| else: | |
| return "" | |
| embed_url = f"https://www.youtube.com/embed/{video_id}" | |
| return f'<iframe width="100%" height="200" src="{embed_url}" style="border-radius:10px"></iframe>' | |
| from pytube import YouTube | |
| import os | |
| from pydub import AudioSegment | |
| def download_audio_from_youtube(video_url): | |
| try: | |
| yt = YouTube(video_url) | |
| audio_stream = yt.streams.filter(only_audio=True).first() | |
| downloaded_file = audio_stream.download(".") | |
| base, ext = os.path.splitext(downloaded_file) | |
| mp3_file = base + '.mp3' | |
| AudioSegment.from_file(downloaded_file).export(mp3_file, format='mp3') | |
| os.remove(downloaded_file) | |
| return base | |
| except Exception as e: | |
| gr.Error(f"An error occurred: {e}") | |
| import ffmpeg | |
| def convert_video_to_audio(input_file): | |
| output_file = "audio.mp3" | |
| try: | |
| ( | |
| ffmpeg | |
| .input(input_file) | |
| .output(output_file) | |
| .run() | |
| ) | |
| return output_file | |
| except ffmpeg.Error as e: | |
| gr.Error(f"An error occurred: {e}") | |
| def transcribe(source, file): | |
| if source == "Audio": | |
| with gr.Blocks(theme="freddyaboulton/test-blue") as demo: | |
| gr.Markdown("<center><h1> ๐ Transcribe Anything </h1></center>") | |
| with gr.Tab("Input"): | |
| with gr.Row(): | |
| with gr.Column(): | |
| source = gr.Radio(label="Source type", choices=[("Audio", "audio"), ("Video", "video"), ("YouTube URL", "youtube")], value="Audio") | |
| def show_source(s): | |
| if s == "Audio": | |
| gr.Audio() | |
| elif s == "Video": | |
| gr.Video() | |
| elif s == "YouTube URL": | |
| t = gr.Textbox(placeholder="https://www.youtube.com/watch?v=44vi31hehw4") | |
| h = gr.HTML(label="Video preview") | |
| t.change(convert_to_embed_url, t, h) | |
| with gr.Column(): | |
| gr.Dropdown(label="Languages", choices=["(Autodetect)", "English"], value="(Autodetect)") | |
| gr.CheckboxGroup(label="Cleanup Transcript with LLM", choices=["Remove typos", "Separate into paragraphs"]) | |
| gr.Checkbox(label="Diarize Speakers (coming soon)", interactive=False) | |
| transcribe_btn = gr.Button("Transcribe!") | |
| with gr.Tab("Result"): | |
| pass | |
| with gr.Tab("Summarize"): | |
| pass | |
| with gr.Tab("Chat"): | |
| pass | |
| demo.launch() |