File size: 1,226 Bytes
9c80799
 
23160a8
 
72ac970
9c80799
 
23160a8
 
 
 
 
 
 
 
 
 
 
 
f776b64
 
 
 
 
9c80799
f776b64
23160a8
 
 
 
 
 
 
 
 
 
 
72ac970
 
9c80799
 
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
"""Application file."""

from pathlib import Path

import evaluate
import gradio as gr


module = evaluate.load("Natooz/ece")

# 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()