dalmeow commited on
Commit
77b8c14
·
1 Parent(s): e010778

Update app.py

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