danieldux commited on
Commit
08d668a
1 Parent(s): 1b08da5

Refactor Gradio interface and add parsed test cases

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -36,18 +36,21 @@ def launch_gradio_widget(metric, test_cases):
36
  (feature_names, feature_types) = zip(*metric.features.items())
37
  gradio_input_types = infer_gradio_input_types(feature_types)
38
 
 
 
39
  def compute(data):
40
  return metric.compute(**parse_gradio_data(data, gradio_input_types))
41
 
42
- iface = gr.Interface(
43
  fn=compute,
44
- inputs=gr.inputs.Dataframe(
 
45
  headers=feature_names,
46
  col_count=len(feature_names),
47
- row_count=5,
48
  datatype=json_to_string_type(gradio_input_types),
 
49
  ),
50
- outputs=gr.outputs.Textbox(label=metric.name),
51
  description=(
52
  metric.info.description
53
  + "\nISCO codes must be wrapped in double quotes."
@@ -56,11 +59,15 @@ def launch_gradio_widget(metric, test_cases):
56
  title=f"Metric: {metric.name}",
57
  article=parse_readme(local_path / "README.md"),
58
  # TODO: load test cases and use them to populate examples
59
- examples=[parse_test_cases(test_cases, feature_names, gradio_input_types)],
60
  )
61
- iface.launch()
 
 
 
62
 
63
 
64
  module = evaluate.load("danieldux/isco_hierarchical_accuracy")
65
 
66
- launch_gradio_widget(module, test_cases)
 
 
36
  (feature_names, feature_types) = zip(*metric.features.items())
37
  gradio_input_types = infer_gradio_input_types(feature_types)
38
 
39
+ parsed_test_cases = parse_test_cases(test_cases, feature_names, gradio_input_types)
40
+
41
  def compute(data):
42
  return metric.compute(**parse_gradio_data(data, gradio_input_types))
43
 
44
+ demo = gr.Interface(
45
  fn=compute,
46
+ inputs=gr.Dataframe(
47
+ value=parsed_test_cases[0],
48
  headers=feature_names,
49
  col_count=len(feature_names),
 
50
  datatype=json_to_string_type(gradio_input_types),
51
+ # row_count=5,
52
  ),
53
+ outputs=gr.Textbox(label=metric.name),
54
  description=(
55
  metric.info.description
56
  + "\nISCO codes must be wrapped in double quotes."
 
59
  title=f"Metric: {metric.name}",
60
  article=parse_readme(local_path / "README.md"),
61
  # TODO: load test cases and use them to populate examples
62
+ examples=[parsed_test_cases],
63
  )
64
+ if __name__ == "__main__":
65
+ demo.launch()
66
+ else:
67
+ return demo
68
 
69
 
70
  module = evaluate.load("danieldux/isco_hierarchical_accuracy")
71
 
72
+ if __name__ == "__main__":
73
+ launch_gradio_widget(module, test_cases)