Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
from jiwer import wer | |
import re | |
import os | |
REGEX_YAML_BLOCK = re.compile(r"---[\n\r]+([\S\s]*?)[\n\r]+---[\n\r]") | |
def parse_readme(filepath): | |
"""Parses a repositories README and removes""" | |
if not os.path.exists(filepath): | |
return "No README.md found." | |
with open(filepath, "r") as f: | |
text = f.read() | |
match = REGEX_YAML_BLOCK.search(text) | |
if match: | |
text = text[match.end() :] | |
return text | |
def compute(input): | |
preds = input['prediction'].tolist() | |
truths = input['truth'].tolist() | |
print(truths, preds, type(truths)) | |
err = wer(truths, preds) | |
print(err) | |
return err | |
description = """ | |
To calculate WER: | |
* Type the `prediction` and the `truth` in the respective columns in the below calculator. | |
* You can insert multiple predictions and truths by clicking on the `New row` button. | |
* To calculate the WER after inserting all the texts, click on `Submit`. | |
""" | |
demo = gr.Interface( | |
fn=compute, | |
inputs=gr.components.Dataframe( | |
headers=["prediction", "truth"], | |
col_count=2, | |
row_count=1, | |
label="Input" | |
), | |
outputs=gr.components.Textbox(label="WER"), | |
description=description, | |
title="WER Calculator", | |
article=parse_readme("README.md") | |
) | |
demo.launch() | |