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