File size: 1,086 Bytes
9d33f0e
 
 
 
 
 
 
 
c331c0b
2d40912
9d50949
9d33f0e
 
 
 
 
 
 
dc16537
9d33f0e
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import torch
import time
import whisper
import os

def greet(null):
    string = ""
    device = torch.device('cpu')
    model_list = ['tiny.en', 'base.en', 'small.en', 'medium', 'large-v2']
    fp16_bool = [False]
    path = 'benchmark/'
    file_list = os.listdir(path)
    for i in model_list:
        for k in fp16_bool:
            model = whisper.load_model(name=i, device=device)
            duration_sum = 0
            for idx, j in enumerate(file_list):
                print(j)
                audio = whisper.load_audio(path + j, sr=16000)
                start = time.time()
                result = model.transcribe(audio, language='en', task='transcribe', fp16=k)
                end = time.time()
                duration_sum = duration_sum + end - start
            print("{} model with fp16 {} costs {:.2f}s".format(i, k, duration_sum))
            string += "{} model with fp16 {} costs {:.2f}s".format(i, k, duration_sum) + "\n"
            del model
    return string

iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()