Spaces:
Sleeping
Sleeping
| import sys | |
| from pathlib import Path | |
| import evaluate | |
| import gradio as gr | |
| import polars as pl | |
| from evaluate import parse_readme | |
| metric = evaluate.load("Aye10032/top5_error_rate") | |
| def compute(data): | |
| print(data) | |
| # return metric.compute() | |
| result = { | |
| "predictions": [list(map(int, pred.split(","))) for pred in data["predictions"]], | |
| "references": data["references"].cast(pl.Int64).to_list() | |
| } | |
| print(result) | |
| return metric.compute(**result) | |
| local_path = Path(sys.path[0]) | |
| default_value = pl.DataFrame({ | |
| 'predictions': ['1,2,3,4,5', '1,2,3,4,5', '1,2,3,4,5'], | |
| 'references': ['0', '1', '2'] | |
| }) | |
| iface = gr.Interface( | |
| fn=compute, | |
| inputs=gr.Dataframe( | |
| headers=['predictions', 'references'], | |
| col_count=2, | |
| row_count=1, | |
| datatype='str', | |
| type='polars', | |
| value=default_value | |
| ), | |
| outputs=gr.Textbox(label=metric.name), | |
| description=( | |
| metric.info.description | |
| + "\nIf this is a text-based metric, make sure to wrap you input in double quotes." | |
| " Alternatively you can use a JSON-formatted list as input." | |
| ), | |
| title=f"Metric: {metric.name}", | |
| article=parse_readme(local_path / "README.md"), | |
| ) | |
| iface.launch() | |