import gradio as gr
import json
from constants import INTRODUCTION_TEXT
from utils import (
init_repo,
load_data,
process_submit,
get_datasets_description,
get_metrics_html,
compute_wer_cer,
get_submit_html,
DATASETS,
)
from styles import LEADERBOARD_CSS
init_repo()
gr.set_static_paths(paths=["."])
with gr.Blocks(css=LEADERBOARD_CSS, theme=gr.themes.Soft()) as demo:
gr.HTML(
'
'
)
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
with gr.Tabs():
with gr.Tab("π
ΠΠΈΠ΄Π΅ΡΠ±ΠΎΡΠ΄"):
leaderboard_html = gr.HTML(value=load_data(), every=60)
with gr.Tab("π ΠΠ΅ΡΡΠΈΠΊΠΈ"):
gr.HTML(get_metrics_html())
with gr.Group():
gr.Markdown("### ΠΠ΅ΡΠΎΡΠ½ΠΈΡΠ°: ΠΏΠΎΡΡΠΈΡΠ°ΠΉΡΠ΅ WER/CER Π½Π° ΡΠ²ΠΎΠΈΡ
ΡΡΡΠΎΠΊΠ°Ρ
")
with gr.Row():
ref = gr.Textbox(
label="Π Π΅ΡΠ΅ΡΠ΅Π½ΡΠ½ΡΠΉ ΡΠ΅ΠΊΡΡ",
placeholder="Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ: Ρ Π»ΡΠ±Π»Ρ ΠΌΠ°ΡΠΈΠ½Π½ΠΎΠ΅ ΠΎΠ±ΡΡΠ΅Π½ΠΈΠ΅",
lines=2,
)
hyp = gr.Textbox(
label="ΠΠΈΠΏΠΎΡΠ΅Π·Π° (ΡΠ°ΡΠΏΠΎΠ·Π½Π°Π½Π½ΡΠΉ ΡΠ΅ΠΊΡΡ)",
placeholder="Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ: Ρ Π»ΡΠ±Π»Ρ ΠΌΠΎΡΠΈΠ½Π½ΠΎΠ΅ ΠΎΠ±ΡΡΠ΅Π½ΠΈΠ΅",
lines=2,
)
with gr.Row():
normalize = gr.Checkbox(
value=True,
label="ΠΠΎΡΠΌΠ°Π»ΠΈΠ·ΠΎΠ²Π°ΡΡ (Π½ΠΈΠΆΠ½ΠΈΠΉ ΡΠ΅Π³ΠΈΡΡΡ, Π±Π΅Π· ΠΏΡΠ½ΠΊΡΡΠ°ΡΠΈΠΈ)",
)
btn_calc = gr.Button("ΠΠΎΡΡΠΈΡΠ°ΡΡ")
with gr.Row():
out_wer = gr.Number(label="WER, %", precision=2)
out_cer = gr.Number(label="CER, %", precision=2)
def _ui_compute(ref_text, hyp_text, norm):
wer, cer = compute_wer_cer(ref_text or "", hyp_text or "", norm)
return wer, cer
btn_calc.click(
_ui_compute,
inputs=[ref, hyp, normalize],
outputs=[out_wer, out_cer],
)
with gr.Tab("π ΠΠ°ΡΠ°ΡΠ΅ΡΡ"):
gr.HTML(get_datasets_description())
with gr.Tab("βοΈ ΠΡΠΏΡΠ°Π²ΠΈΡΡ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ"):
gr.HTML(get_submit_html())
with gr.Row():
with gr.Column():
model_name = gr.Textbox(
label="ΠΠ°Π·Π²Π°Π½ΠΈΠ΅ ΠΌΠΎΠ΄Π΅Π»ΠΈ *", placeholder="MyAwesomeASRModel"
)
link = gr.Textbox(
label="Π‘ΡΡΠ»ΠΊΠ° Π½Π° ΠΌΠΎΠ΄Π΅Π»Ρ *",
placeholder="https://huggingface.co/username/model",
)
license_field = gr.Textbox(
label="ΠΠΈΡΠ΅Π½Π·ΠΈΡ *", placeholder="MIT / Apache-2.0 / Closed"
)
with gr.Column():
metrics_json = gr.TextArea(
label="ΠΠ΅ΡΡΠΈΠΊΠΈ JSON *",
placeholder='{"Russian_LibriSpeech": {"wer": 0.1234, "cer": 0.0567}, ...}',
lines=16,
)
submit_btn = gr.Button("π ΠΡΠΏΡΠ°Π²ΠΈΡΡ", elem_classes="full-width-btn")
output_msg = gr.HTML()
def _alert(kind, text):
return f'