Spaces:
Sleeping
Sleeping
File size: 1,501 Bytes
f73471d fa3603e f73471d fa3603e f73471d | 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import gradio as gr
from script_fidelity import compute_corpus_sfr, list_languages
EXAMPLE_TEXT = "کابل کې ښه هوا ده\nromanized output"
def _score(predictions_text: str, language: str, digit_policy: str) -> dict:
predictions = [
line.strip()
for line in (predictions_text or "").splitlines()
if line.strip()
]
if not predictions:
return {"error": "Enter at least one prediction."}
return compute_corpus_sfr(
predictions,
language=language,
digit_policy=digit_policy,
return_details=True,
)
with gr.Blocks(title="Script Fidelity Rate") as demo:
gr.Markdown(
"# Script Fidelity Rate\n"
"Reference-free script check for multilingual ASR. "
"Enter one prediction per line."
)
with gr.Row():
language = gr.Dropdown(
choices=list_languages(),
value="ps_af",
label="FLEURS language",
)
digit_policy = gr.Radio(
choices=["count", "ignore"],
value="count",
label="Digit policy",
)
predictions = gr.Textbox(
value=EXAMPLE_TEXT,
lines=6,
label="Predictions",
)
button = gr.Button("Compute SFR")
output = gr.JSON(label="Result")
button.click(_score, [predictions, language, digit_policy], output)
predictions.submit(_score, [predictions, language, digit_policy], output)
if __name__ == "__main__":
demo.launch()
|