Spaces:
Runtime error
Runtime error
import evaluate | |
from evaluate.utils import parse_readme, infer_gradio_input_types, json_to_string_type,parse_gradio_data | |
import re | |
import sys | |
from pathlib import Path | |
from evaluate.utils.logging import get_logger | |
logger = get_logger(__name__) | |
REGEX_YAML_BLOCK = re.compile(r"---[\n\r]+([\S\s]*?)[\n\r]+---[\n\r]") | |
module = evaluate.load("JP-SystemsX/nDCG") | |
def launch_gradio_widget(metric): | |
"""Launches `metric` widget with Gradio.""" | |
try: | |
import gradio as gr | |
except ImportError as error: | |
logger.error("To create a metric widget with Gradio make sure gradio is installed.") | |
raise error | |
local_path = Path(sys.path[0]) | |
# if there are several input types, use first as default. | |
if isinstance(metric.features, list): | |
(feature_names, feature_types) = zip(*metric.features[0].items()) | |
else: | |
(feature_names, feature_types) = zip(*metric.features.items()) | |
gradio_input_types = infer_gradio_input_types(feature_types) | |
def compute(data): | |
return metric.compute(**parse_gradio_data(data, gradio_input_types)) | |
iface = gr.Interface( | |
fn=compute, | |
inputs=gr.inputs.Dataframe( | |
headers=feature_names, | |
col_count=len(feature_names), | |
row_count=2, | |
datatype=json_to_string_type(gradio_input_types), | |
default=[['[1,2,3]','[1,2,3]'],['[1,1,0]','[0,1,1]']] | |
), | |
outputs=gr.outputs.Textbox(label=metric.name), | |
description=metric.info.description, | |
title=f"Metric: {metric.name}", | |
article=parse_readme(local_path / "README.md"), | |
) | |
iface.launch() | |
x = launch_gradio_widget(module) | |