File size: 2,843 Bytes
bb13dff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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")
                @gr.render(inputs=source)
                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()