|
from transformers import pipeline |
|
import gradio as gr |
|
import time |
|
from video_downloader import download_video |
|
from moviepy.editor import AudioFileClip |
|
import datetime |
|
import os |
|
from pydub import AudioSegment |
|
from pydub.silence import split_on_silence |
|
|
|
pipe = pipeline("automatic-speech-recognition", model="Artanis1551/whisper_romanian3") |
|
|
|
|
|
def process_video(date, live): |
|
|
|
date = datetime.datetime.strptime(date, "%Y-%m-%d").strftime("%Y%m%d") |
|
|
|
|
|
video_path = download_video(date) |
|
|
|
|
|
live.update(video_path) |
|
|
|
|
|
audio_path = f"audio_{date}.wav" |
|
AudioFileClip(video_path).write_audiofile(audio_path) |
|
|
|
|
|
audio = AudioSegment.from_wav(audio_path) |
|
chunks = split_on_silence(audio, min_silence_len=500, silence_thresh=-40) |
|
|
|
|
|
transcription = "" |
|
for i, chunk in enumerate(chunks): |
|
chunk.export(f"chunk{i}.wav", format="wav") |
|
with open(f"chunk{i}.wav", "rb") as audio_file: |
|
audio = audio_file.read() |
|
transcription += pipe(audio)["text"] + "\n " |
|
os.remove(f"chunk{i}.wav") |
|
|
|
|
|
live.update(video_path, transcription) |
|
|
|
|
|
os.remove(audio_path) |
|
|
|
|
|
iface = gr.Interface( |
|
fn=process_video, |
|
inputs=gr.inputs.Textbox(label="Date with format YYYYMMDD"), |
|
outputs=[ |
|
gr.outputs.Video(), |
|
gr.Textbox(lines=1000, max_lines=1000, interactive=True), |
|
], |
|
live=True, |
|
title="Romanian Transcription Test", |
|
) |
|
|
|
iface.launch() |
|
|