j-tobias
added backend
752ce9b
raw
history blame
3.82 kB
import gradio as gr # needs to be installed
from dataset import Dataset
from model import Model
from utils import hf_login, compute_wer
hf_login()
dataset = Dataset()
models = Model()
def run_tests (dataset_choice:str, model:str):
MoDeL = Model()
MoDeL.select(model)
MoDeL.load()
DaTaSeT = Dataset(100)
DaTaSeT.load(dataset_choice)
references, predictions = MoDeL.process(DaTaSeT)
wer = compute_wer(references=references, predictions=predictions)
return wer
def eval(data_subset:str, model_1:str, model_2:str)->str:
wer_result_1 = run_tests(data_subset, model_1)
wer_result_2 = run_tests(data_subset, model_2)
return f"WER Score: {wer_result_1}", f"WER Score: {wer_result_2}"
def get_card(selected_model:str)->str:
if selected_model == "None":
return ""
elif selected_model == "Model2":
return "A very good model indeed"
elif selected_model == "Model3":
return "Also very good"
else:
return "Unknown Model"
def is_own(data_subset:str):
if data_subset == "own":
own_audio = gr.Audio(sources=['microphone'],streaming=False)
own_transcription = gr.TextArea(lines=2)
return own_audio, own_transcription
own_audio = None
own_transcription = None
return own_audio, own_transcription
with gr.Blocks() as demo:
gr.Markdown('# <p style="text-align: center;">VocalVenturer 💬</p>')
gr.Markdown("-------")
gr.Markdown("""#### Hello there, this is the VocalVenturer, this app is aimed at helping you making more informed model choices for ASR. Please choose a Data Subset to evalutate the Models on. You also have the opportunity to record and transcibe an own sample. The Models will be evaluated using the *WER* metric -> here is an amazing Leaderboard for it LINK""")
with gr.Row():
with gr.Column(scale=1):
pass
with gr.Column(scale=5):
data_subset = gr.Radio(
value="LibriSpeech Clean",
choices=dataset.get_options(),
label="Data subset / Own Sample",
)
with gr.Column(scale=1):
pass
with gr.Row():
own_audio = gr.Audio(sources=['microphone'],streaming=False,visible=False)
own_transcription = gr.TextArea(lines=2, visible=False)
data_subset.change(is_own, inputs=[data_subset], outputs=[own_audio, own_transcription])
with gr.Row():
with gr.Column(scale=1):
model_1 = gr.Dropdown(
choices=models.get_options(),
label="Select Model"
)
model_1_card = gr.Markdown("")
with gr.Column(scale=1):
model_2 = gr.Dropdown(
choices=models.get_options(),
label="Select Model"
)
model_2_card = gr.Markdown("")
# with gr.Column(scale=1):
# model_3 = gr.Dropdown(
# choices=models.get_options(),
# label="Select Model"
# )
# model_3_card = gr.Markdown("")
model_1.change(get_card, inputs=model_1, outputs=model_1_card)
model_2.change(get_card, inputs=model_2, outputs=model_2_card)
# model_3.change(get_card, inputs=model_3, outputs=model_3_card)
eval_btn = gr.Button(
value="Evaluate",
variant="primary",
size="sm"
)
gr.Markdown('## <p style="text-align: center;">Results</p>')
gr.Markdown("-------")
with gr.Row():
with gr.Column(scale=1):
results_model_1 = gr.Markdown("")
with gr.Column(scale=1):
results_model_2 = gr.Markdown("")
eval_btn.click(eval, [data_subset, model_1, model_2], [results_model_1, results_model_2])
demo.launch(debug=True)