File size: 1,003 Bytes
fac06d0
 
 
de84263
 
 
 
fac06d0
 
 
 
de84263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d14f075
fac06d0
534a7d7
de84263
 
 
534a7d7
 
 
 
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
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

pipe = pipeline("automatic-speech-recognition", model="Artanis1551/whisper_romanian3")


def process_video(date):
    # Parse the date to the format yyyymmdd
    date = datetime.datetime.strptime(date, "%Y-%m-%d").strftime("%Y%m%d")

    # Download the video
    video_path = download_video(date)

    # Extract audio from the video
    audio_path = f"audio_{date}.wav"
    AudioFileClip(video_path).write_audiofile(audio_path)

    # Transcribe the audio
    with open(audio_path, "rb") as audio_file:
        audio = audio_file.read()
    transcription = pipe(audio)["text"]

    # Remove the audio file
    os.remove(audio_path)

    return video_path, transcription


iface = gr.Interface(
    fn=process_video,
    inputs="date",
    outputs=["video", "text"],
    title="Romanian Transcription Test",
)

iface.launch()