Spaces:
Sleeping
Sleeping
File size: 1,255 Bytes
ab21cd8 afa91bc ab21cd8 afa91bc ab21cd8 afa91bc ab21cd8 |
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 43 44 45 46 47 48 49 50 51 |
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()
|