File size: 717 Bytes
93ec611
 
 
9f1070e
9f13a48
00b55b7
9f13a48
03b7abb
00b55b7
93ec611
9f1070e
93ec611
d818586
19001c8
9f1070e
00b55b7
e460592
19001c8
9f1070e
 
 
93ec611
62e3412
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
import spaces
import torch
import io
import os.path
from huggingface_hub import hf_hub_download
import whisper

model_path = hf_hub_download(repo_id="distil-whisper/distil-large-v3-openai", filename="model.bin")

writer = whisper.utils.get_writer("srt", "/dev/null")

@spaces.GPU
def generate(file, progress=gr.Progress(track_tqdm=True)):
    # get file to type bytes somehow
    model = whisper.load_model(model_path, device="cuda")
    audio = whisper.load_audio(file)
    result = model.transcribe(audio, verbose=False)
    out = io.StringIO()
    writer.write_result(result, out)
    return out.getvalue()

gr.Interface(fn=generate, inputs=gr.File(type="filepath"), outputs=gr.Text()).launch()