Spaces:
Sleeping
Sleeping
John Graham Reynolds
commited on
Commit
·
2488f8b
1
Parent(s):
7ca7f15
a second workaround for deploying metrics to spaces
Browse files
app.py
CHANGED
|
@@ -1,7 +1,40 @@
|
|
| 1 |
import evaluate
|
| 2 |
-
from evaluate.utils import
|
| 3 |
from fixed_f1 import FixedF1
|
|
|
|
| 4 |
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import evaluate
|
| 2 |
+
from evaluate.utils import infer_gradio_input_types, json_to_string_type, parse_readme
|
| 3 |
from fixed_f1 import FixedF1
|
| 4 |
+
# from evaluate.utils import launch_gradio_widget # using this directly is erroneous - lets fix this
|
| 5 |
|
| 6 |
+
metric = FixedF1()
|
| 7 |
|
| 8 |
+
if isinstance(metric.features, list):
|
| 9 |
+
(feature_names, feature_types) = zip(*metric.features[0].items())
|
| 10 |
+
else:
|
| 11 |
+
(feature_names, feature_types) = zip(*metric.features.items())
|
| 12 |
+
gradio_input_types = infer_gradio_input_types(feature_types)
|
| 13 |
+
|
| 14 |
+
gradio_input_types = infer_gradio_input_types(feature_types)
|
| 15 |
+
|
| 16 |
+
def compute():
|
| 17 |
+
metric._compute()
|
| 18 |
+
|
| 19 |
+
import gradio as gr
|
| 20 |
+
|
| 21 |
+
space = gr.Interface(
|
| 22 |
+
fn=compute,
|
| 23 |
+
inputs=gr.Dataframe(
|
| 24 |
+
headers=feature_names,
|
| 25 |
+
col_count=len(feature_names),
|
| 26 |
+
row_count=1,
|
| 27 |
+
datatype=json_to_string_type(gradio_input_types),
|
| 28 |
+
),
|
| 29 |
+
outputs=gr.Textbox(label=metric.name),
|
| 30 |
+
description=(
|
| 31 |
+
metric.info.description + "\nIf this is a text-based metric, make sure to wrap your input in double quotes."
|
| 32 |
+
" Alternatively you can use a JSON-formatted list as input."
|
| 33 |
+
),
|
| 34 |
+
title=f"Metric: {metric.name}",
|
| 35 |
+
article=parse_readme("./README.md"),
|
| 36 |
+
# TODO: load test cases and use them to populate examples
|
| 37 |
+
# examples=[parse_test_cases(test_cases, feature_names, gradio_input_types)]
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
space.launch()
|