|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import gradio as gr |
|
from transformers import pipeline |
|
from moviepy.editor import VideoFileClip |
|
import tempfile |
|
import os |
|
|
|
pipe = pipeline(model="dacavi/whisper-small-hi") |
|
|
|
def transcribe_video(video_url): |
|
|
|
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as temp_video: |
|
os.system(f"youtube-dl -o {temp_video.name} {video_url}") |
|
video_clip = VideoFileClip(temp_video.name) |
|
audio_clip = video_clip.audio |
|
temp_audio_path = tempfile.NamedTemporaryFile(suffix=".wav", delete=False).name |
|
audio_clip.write_audiofile(temp_audio_path, codec="wav") |
|
|
|
|
|
text = pipe(temp_audio_path)["text"] |
|
|
|
|
|
os.remove(temp_video.name) |
|
os.remove(temp_audio_path) |
|
|
|
return text |
|
|
|
iface = gr.Interface( |
|
fn=transcribe_video, |
|
inputs="text", |
|
outputs="text", |
|
live=True, |
|
title="Video Transcription", |
|
description="Paste the URL of a video to transcribe the spoken content.", |
|
) |
|
|
|
iface.launch() |
|
|