|
import gradio as gr |
|
import whisper |
|
import os |
|
from moviepy.editor import VideoFileClip |
|
|
|
model = whisper.load_model("base") |
|
|
|
def transcribe_media(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"] |
|
|
|
demo = gr.Interface( |
|
fn=transcribe_media, |
|
inputs=gr.File(label="π¬ mp4 / mp3 / wav νμΌ μ
λ‘λ"), |
|
outputs="text", |
|
title="π€ Whisper μμ± μ μ¬κΈ°", |
|
description="mp4 μμ λλ mp3/wav μμ± νμΌμ ν
μ€νΈλ‘ λ³νν©λλ€.", |
|
allow_flagging="never" |
|
) |
|
|
|
demo.launch() |
|
|