Spaces:
Runtime error
Runtime error
saicharan2804
commited on
Commit
·
b7c3800
1
Parent(s):
26f36e1
gradio change
Browse files
app.py
CHANGED
@@ -1,6 +1,42 @@
|
|
1 |
-
|
2 |
-
|
3 |
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import evaluate
|
2 |
+
from evaluate.utils import launch_gradio_widget
|
3 |
|
4 |
|
5 |
+
module = evaluate.load("saicharan2804/my_metric")
|
6 |
+
try:
|
7 |
+
import gradio as gr
|
8 |
+
except ImportError as error:
|
9 |
+
logger.error("To create a metric widget with Gradio make sure gradio is installed.")
|
10 |
+
raise error
|
11 |
+
|
12 |
+
local_path = Path(sys.path[0])
|
13 |
+
# if there are several input types, use first as default.
|
14 |
+
if isinstance(metric.features, list):
|
15 |
+
(feature_names, feature_types) = zip(*metric.features[0].items())
|
16 |
+
else:
|
17 |
+
(feature_names, feature_types) = zip(*metric.features.items())
|
18 |
+
gradio_input_types = infer_gradio_input_types(feature_types)
|
19 |
+
|
20 |
+
def compute(data):
|
21 |
+
return metric.compute(**parse_gradio_data(data, gradio_input_types))
|
22 |
+
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=compute,
|
25 |
+
inputs=gr.Dataframe(
|
26 |
+
headers=feature_names,
|
27 |
+
col_count=len(feature_names),
|
28 |
+
row_count=1,
|
29 |
+
datatype=json_to_string_type(gradio_input_types),
|
30 |
+
),
|
31 |
+
outputs=gr.Textbox(label=metric.name),
|
32 |
+
description=(
|
33 |
+
metric.info.description + "\nIf this is a text-based metric, make sure to wrap you input in double quotes."
|
34 |
+
" Alternatively you can use a JSON-formatted list as input."
|
35 |
+
),
|
36 |
+
title=f"Metric: {metric.name}",
|
37 |
+
article=parse_readme(local_path / "README.md"),
|
38 |
+
# TODO: load test cases and use them to populate examples
|
39 |
+
# examples=[parse_test_cases(test_cases, feature_names, gradio_input_types)]
|
40 |
+
)
|
41 |
+
|
42 |
+
iface.launch()
|