Spaces:
Sleeping
Sleeping
| 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() | |