Spaces:
Sleeping
Sleeping
"""Application file.""" | |
from pathlib import Path | |
import evaluate | |
import gradio as gr | |
module = evaluate.load("Natooz/levenshtein") | |
# Code taken and adapted from: https://github.com/huggingface/evaluate/blob/main/src/evaluate/utils/gradio.py | |
local_path = Path(__file__).parent | |
# if there are several input types, use first as default. | |
if isinstance(module.features, list): | |
(feature_names, feature_types) = zip(*module.features[0].items()) | |
else: | |
(feature_names, feature_types) = zip(*module.features.items()) | |
gradio_input_types = evaluate.utils.infer_gradio_input_types(feature_types) | |
def compute(data): | |
return module.compute(**evaluate.utils.parse_gradio_data(data, gradio_input_types)) | |
gradio_app = gr.Interface( | |
fn=compute, | |
inputs=gr.Dataframe( | |
headers=feature_names, | |
col_count=len(feature_names), | |
row_count=1, | |
datatype=evaluate.utils.json_to_string_type(gradio_input_types), | |
), | |
outputs=gr.Textbox(label=module.name), | |
description=module.info.description, | |
title=f"Metric: {module.name}", | |
article=evaluate.utils.parse_readme(local_path / "README.md"), | |
) | |
if __name__ == "__main__": | |
gradio_app.launch() | |