Spaces:
Runtime error
Runtime error
JP-SystemsX
commited on
Commit
·
51467b5
1
Parent(s):
0a60649
Added a default value to the interactive example
Browse files
app.py
CHANGED
@@ -1,6 +1,51 @@
|
|
1 |
import evaluate
|
2 |
-
from evaluate.utils import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
module = evaluate.load("nDCG.py")
|
5 |
|
6 |
-
launch_gradio_widget(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import evaluate
|
2 |
+
from evaluate.utils import parse_readme, infer_gradio_input_types, json_to_string_type,parse_gradio_data
|
3 |
+
import re
|
4 |
+
import sys
|
5 |
+
from pathlib import Path
|
6 |
+
|
7 |
+
from evaluate.utils.logging import get_logger
|
8 |
+
|
9 |
+
logger = get_logger(__name__)
|
10 |
+
REGEX_YAML_BLOCK = re.compile(r"---[\n\r]+([\S\s]*?)[\n\r]+---[\n\r]")
|
11 |
|
12 |
module = evaluate.load("nDCG.py")
|
13 |
|
14 |
+
def launch_gradio_widget(metric):
|
15 |
+
"""Launches `metric` widget with Gradio."""
|
16 |
+
|
17 |
+
try:
|
18 |
+
import gradio as gr
|
19 |
+
except ImportError as error:
|
20 |
+
logger.error("To create a metric widget with Gradio make sure gradio is installed.")
|
21 |
+
raise error
|
22 |
+
|
23 |
+
local_path = Path(sys.path[0])
|
24 |
+
# if there are several input types, use first as default.
|
25 |
+
if isinstance(metric.features, list):
|
26 |
+
(feature_names, feature_types) = zip(*metric.features[0].items())
|
27 |
+
else:
|
28 |
+
(feature_names, feature_types) = zip(*metric.features.items())
|
29 |
+
gradio_input_types = infer_gradio_input_types(feature_types)
|
30 |
+
|
31 |
+
def compute(data):
|
32 |
+
return metric.compute(**parse_gradio_data(data, gradio_input_types))
|
33 |
+
|
34 |
+
iface = gr.Interface(
|
35 |
+
fn=compute,
|
36 |
+
inputs=gr.inputs.Dataframe(
|
37 |
+
headers=feature_names,
|
38 |
+
col_count=len(feature_names),
|
39 |
+
row_count=2,
|
40 |
+
datatype=json_to_string_type(gradio_input_types),
|
41 |
+
default=[['[1,2,3]','[1,2,3]'],['[1,1,0]','[0,1,1]']]
|
42 |
+
),
|
43 |
+
outputs=gr.outputs.Textbox(label=metric.name),
|
44 |
+
description=metric.info.description,
|
45 |
+
title=f"Metric: {metric.name}",
|
46 |
+
article=parse_readme(local_path / "README.md"),
|
47 |
+
)
|
48 |
+
|
49 |
+
iface.launch()
|
50 |
+
|
51 |
+
x = launch_gradio_widget(module)
|
nDCG.py
CHANGED
@@ -18,6 +18,7 @@ scores in the ranking
|
|
18 |
|
19 |
References
|
20 |
----------
|
|
|
21 |
`Wikipedia entry for Discounted Cumulative Gain
|
22 |
<https://en.wikipedia.org/wiki/Discounted_cumulative_gain>`_
|
23 |
|
@@ -27,7 +28,7 @@ References
|
|
27 |
|
28 |
Wang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May).
|
29 |
A theoretical analysis of NDCG ranking measures. In Proceedings of the 26th
|
30 |
-
Annual Conference on Learning Theory (COLT 2013)
|
31 |
|
32 |
McSherry, F., & Najork, M. (2008, March). Computing information retrieval
|
33 |
performance measures efficiently in the presence of tied scores. In
|
|
|
18 |
|
19 |
References
|
20 |
----------
|
21 |
+
|
22 |
`Wikipedia entry for Discounted Cumulative Gain
|
23 |
<https://en.wikipedia.org/wiki/Discounted_cumulative_gain>`_
|
24 |
|
|
|
28 |
|
29 |
Wang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May).
|
30 |
A theoretical analysis of NDCG ranking measures. In Proceedings of the 26th
|
31 |
+
Annual Conference on Learning Theory (COLT 2013).
|
32 |
|
33 |
McSherry, F., & Najork, M. (2008, March). Computing information retrieval
|
34 |
performance measures efficiently in the presence of tied scores. In
|