File size: 1,622 Bytes
ed33df7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import whisper
import os
from pytube import YouTube
from moviepy.editor import VideoFileClip

model = whisper.load_model("base")

def download_youtube_audio(url):
    yt = YouTube(url)
    stream = yt.streams.filter(only_audio=True).first()
    audio_file = stream.download(filename="yt_audio.mp4")
    return audio_file

def transcribe_from_file(file):
    filename, ext = os.path.splitext(file)
    if ext == ".mp4":
        video = VideoFileClip(file)
        audio_path = filename + ".mp3"
        video.audio.write_audiofile(audio_path)
        result = model.transcribe(audio_path)
        os.remove(audio_path)
    else:
        result = model.transcribe(file)
    return result["text"]

def transcribe_combined(file, url):
    if url:
        try:
            downloaded = download_youtube_audio(url)
            return transcribe_from_file(downloaded)
        except Exception as e:
            return f"❌ 유튜브 λ‹€μš΄λ‘œλ“œ μ‹€νŒ¨: {str(e)}"
    elif file:
        return transcribe_from_file(file)
    else:
        return "⚠️ νŒŒμΌμ΄λ‚˜ URL 쀑 ν•˜λ‚˜λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”."

demo = gr.Interface(
    fn=transcribe_combined,
    inputs=[
        gr.File(label="🎬 파일 μ—…λ‘œλ“œ (선택)", file_types=[".mp3", ".wav", ".mp4"]),
        gr.Textbox(label="πŸ“Ž YouTube 링크 (선택)", placeholder="https://youtu.be/...")
    ],
    outputs="text",
    title="🎧 Whisper 전사기 + YouTube 지원",
    description="mp4/mp3/wav νŒŒμΌμ„ μ—…λ‘œλ“œν•˜κ±°λ‚˜ YouTube μ˜μƒ μ£Όμ†Œλ₯Ό λΆ™μ—¬λ„£μ–΄ ν…μŠ€νŠΈλ‘œ μ „μ‚¬ν•˜μ„Έμš”!",
    allow_flagging="never"
)

demo.launch()