jogonba2 commited on
Commit
019cdb7
·
1 Parent(s): 370eab2

float casting

Browse files
Files changed (2) hide show
  1. gradio_tst.py +21 -11
  2. regression_evaluator.py +1 -1
gradio_tst.py CHANGED
@@ -1,4 +1,5 @@
1
  import json
 
2
  import os
3
  import re
4
  import sys
@@ -7,10 +8,6 @@ from pathlib import Path
7
  import numpy as np
8
  from datasets import Value
9
 
10
- import logging
11
-
12
-
13
-
14
  REGEX_YAML_BLOCK = re.compile(r"---[\n\r]+([\S\s]*?)[\n\r]+---[\n\r]")
15
 
16
 
@@ -27,7 +24,9 @@ def infer_gradio_input_types(feature_types):
27
  for feature_type in feature_types:
28
  input_type = "json"
29
  if isinstance(feature_type, Value):
30
- if feature_type.dtype.startswith("int") or feature_type.dtype.startswith("float"):
 
 
31
  input_type = "number"
32
  elif feature_type.dtype == "string":
33
  input_type = "str"
@@ -59,9 +58,13 @@ def parse_gradio_data(data, input_types):
59
  data.dropna(inplace=True)
60
  for feature_name, input_type in zip(data, input_types):
61
  if input_type == "json":
62
- metric_inputs[feature_name] = [json.loads(d) for d in data[feature_name].to_list()]
 
 
63
  elif input_type == "str":
64
- metric_inputs[feature_name] = [d.strip('"') for d in data[feature_name].to_list()]
 
 
65
  else:
66
  metric_inputs[feature_name] = data[feature_name]
67
  return metric_inputs
@@ -79,9 +82,13 @@ def parse_test_cases(test_cases, feature_names, input_types):
79
  parsed_cases = []
80
  for feat, input_type in zip(feature_names, input_types):
81
  if input_type == "json":
82
- parsed_cases.append([str(element) for element in test_case[feat]])
 
 
83
  elif input_type == "str":
84
- parsed_cases.append(['"' + element + '"' for element in test_case[feat]])
 
 
85
  else:
86
  parsed_cases.append(test_case[feat])
87
  examples.append([list(i) for i in zip(*parsed_cases)])
@@ -94,7 +101,9 @@ def launch_gradio_widget2(metric):
94
  try:
95
  import gradio as gr
96
  except ImportError as error:
97
- logging.error("To create a metric widget with Gradio make sure gradio is installed.")
 
 
98
  raise error
99
 
100
  local_path = Path(sys.path[0])
@@ -118,7 +127,8 @@ def launch_gradio_widget2(metric):
118
  ),
119
  outputs=gr.Textbox(label=metric.name),
120
  description=(
121
- metric.info.description + "\nIf this is a text-based metric, make sure to wrap you input in double quotes."
 
122
  " Alternatively you can use a JSON-formatted list as input."
123
  ),
124
  title=f"Metric: {metric.name}",
 
1
  import json
2
+ import logging
3
  import os
4
  import re
5
  import sys
 
8
  import numpy as np
9
  from datasets import Value
10
 
 
 
 
 
11
  REGEX_YAML_BLOCK = re.compile(r"---[\n\r]+([\S\s]*?)[\n\r]+---[\n\r]")
12
 
13
 
 
24
  for feature_type in feature_types:
25
  input_type = "json"
26
  if isinstance(feature_type, Value):
27
+ if feature_type.dtype.startswith(
28
+ "int"
29
+ ) or feature_type.dtype.startswith("float"):
30
  input_type = "number"
31
  elif feature_type.dtype == "string":
32
  input_type = "str"
 
58
  data.dropna(inplace=True)
59
  for feature_name, input_type in zip(data, input_types):
60
  if input_type == "json":
61
+ metric_inputs[feature_name] = [
62
+ json.loads(d) for d in data[feature_name].to_list()
63
+ ]
64
  elif input_type == "str":
65
+ metric_inputs[feature_name] = [
66
+ d.strip('"') for d in data[feature_name].to_list()
67
+ ]
68
  else:
69
  metric_inputs[feature_name] = data[feature_name]
70
  return metric_inputs
 
82
  parsed_cases = []
83
  for feat, input_type in zip(feature_names, input_types):
84
  if input_type == "json":
85
+ parsed_cases.append(
86
+ [str(element) for element in test_case[feat]]
87
+ )
88
  elif input_type == "str":
89
+ parsed_cases.append(
90
+ ['"' + element + '"' for element in test_case[feat]]
91
+ )
92
  else:
93
  parsed_cases.append(test_case[feat])
94
  examples.append([list(i) for i in zip(*parsed_cases)])
 
101
  try:
102
  import gradio as gr
103
  except ImportError as error:
104
+ logging.error(
105
+ "To create a metric widget with Gradio make sure gradio is installed."
106
+ )
107
  raise error
108
 
109
  local_path = Path(sys.path[0])
 
127
  ),
128
  outputs=gr.Textbox(label=metric.name),
129
  description=(
130
+ metric.info.description
131
+ + "\nIf this is a text-based metric, make sure to wrap you input in double quotes."
132
  " Alternatively you can use a JSON-formatted list as input."
133
  ),
134
  title=f"Metric: {metric.name}",
regression_evaluator.py CHANGED
@@ -97,7 +97,7 @@ class RegressionEvaluator(evaluate.Metric):
97
 
98
  # Compute error functions
99
  for fn in error_fns:
100
- results[fn.__name__] = fn(references, predictions)
101
 
102
  # Compute statistical measures with p-values
103
  for fn in correlation_fns:
 
97
 
98
  # Compute error functions
99
  for fn in error_fns:
100
+ results[fn.__name__] = float(fn(references, predictions))
101
 
102
  # Compute statistical measures with p-values
103
  for fn in correlation_fns: