John Graham Reynolds commited on
Commit
0b0e7aa
·
1 Parent(s): c5503a4

add test cases and try out readme parser as defined in the lib

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -1,8 +1,15 @@
 
 
 
1
  import evaluate
2
- from evaluate.utils import infer_gradio_input_types, json_to_string_type, parse_readme
3
  # from evaluate.utils import launch_gradio_widget # using this directly is erroneous - lets fix this
4
  from fixed_f1 import FixedF1
5
- import gradio as gr
 
 
 
 
6
 
7
  metric = FixedF1()
8
 
@@ -10,19 +17,18 @@ 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
  gradio_input_types = infer_gradio_input_types(feature_types)
16
 
17
- def compute():
18
- metric._compute()
19
 
20
  space = gr.Interface(
21
  fn=compute,
22
  inputs=gr.Dataframe(
23
  headers=feature_names,
24
  col_count=len(feature_names),
25
- row_count=1,
26
  datatype=json_to_string_type(gradio_input_types),
27
  ),
28
  outputs=gr.Textbox(label=metric.name),
@@ -31,9 +37,9 @@ space = gr.Interface(
31
  " Alternatively you can use a JSON-formatted list as input."
32
  ),
33
  title=f"Metric: {metric.name}",
34
- article=parse_readme("./README.md"),
35
  # TODO: load test cases and use them to populate examples
36
- # examples=[parse_test_cases(test_cases, feature_names, gradio_input_types)]
37
  )
38
 
39
  space.launch()
 
1
+ import sys
2
+ import gradio as gr
3
+ import pandas as pd
4
  import evaluate
5
+ from evaluate.utils import infer_gradio_input_types, json_to_string_type, parse_readme, parse_test_cases
6
  # from evaluate.utils import launch_gradio_widget # using this directly is erroneous - lets fix this
7
  from fixed_f1 import FixedF1
8
+ from pathlib import Path
9
+
10
+ def compute(input: pd.DataFrame):
11
+
12
+ metric._compute()
13
 
14
  metric = FixedF1()
15
 
 
17
  (feature_names, feature_types) = zip(*metric.features[0].items())
18
  else:
19
  (feature_names, feature_types) = zip(*metric.features.items())
 
20
 
21
  gradio_input_types = infer_gradio_input_types(feature_types)
22
 
23
+ local_path = Path(sys.path[0])
24
+ test_cases = [ {"predictions":[1,2,3,4,5], "references":[1,2,5,4,3]} ] # configure this randomly using randint generator and feature names?
25
 
26
  space = gr.Interface(
27
  fn=compute,
28
  inputs=gr.Dataframe(
29
  headers=feature_names,
30
  col_count=len(feature_names),
31
+ row_count=5,
32
  datatype=json_to_string_type(gradio_input_types),
33
  ),
34
  outputs=gr.Textbox(label=metric.name),
 
37
  " Alternatively you can use a JSON-formatted list as input."
38
  ),
39
  title=f"Metric: {metric.name}",
40
+ article=parse_readme(local_path / "README.md"),
41
  # TODO: load test cases and use them to populate examples
42
+ examples=[parse_test_cases(test_cases, feature_names, gradio_input_types)]
43
  )
44
 
45
  space.launch()