Soptq commited on
Commit
9b27ece
·
verified ·
1 Parent(s): 4517813

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -12
app.py CHANGED
@@ -4,7 +4,12 @@ import pandas as pd
4
  from constants import *
5
 
6
 
7
- def get_data(verified, dataset, ipc, label_type):
 
 
 
 
 
8
  data = pd.read_csv("data.csv")
9
  data["verified"] = data["verified"].apply(lambda x: bool(x))
10
  data["dataset"] = data["dataset"].apply(lambda x: DATASET_LIST[x])
@@ -14,17 +19,24 @@ def get_data(verified, dataset, ipc, label_type):
14
  data = data[data["verified"] == verified]
15
  data = data[data["dataset"] == dataset]
16
  data = data[data["ipc"] == ipc]
17
- data = data[data["label_type"] == label_type]
 
 
 
 
 
18
  data = data.sort_values(by="score", ascending=False)
 
19
 
20
  # formatting
21
  data["method"] = "[" + data["method"] + "](" + data["method_reference"] + ")"
22
  data["verified"] = data["verified"].apply(lambda x: "✅" if x else "")
23
- data = data.drop(columns=["method_reference", "dataset", "ipc", "label_type"])
 
24
  if label_type == "Hard Label":
25
- data = data.rename(columns={"method": "Method", "date": "Date", "recovery": "Hard Recovery", "improvement": "Hard Improvement", "score": "Score", "verified": "Verified"})
26
  else:
27
- data = data.rename(columns={"method": "Method", "date": "Date", "recovery": "Hard Recovery", "improvement": "Soft Improvement", "score": "Score", "verified": "Verified"})
28
  return data
29
 
30
 
@@ -50,16 +62,30 @@ with gr.Blocks() as leaderboard:
50
  interactive=True,
51
  info=IPC_INFO
52
  )
53
- label = gr.Radio(
54
  label="Label Type",
55
  choices=LABEL_TYPE_LIST,
56
- value=LABEL_TYPE_LIST[0],
 
57
  interactive=True,
58
- info=LABEL_TYPE_INFO
59
  )
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  board = gr.components.Dataframe(
62
- value=get_data(verified.value, dataset.value, ipc.value, label.value),
63
  headers=COLUMN_NAMES,
64
  type="pandas",
65
  datatype=DATA_TITLE_TYPE,
@@ -69,15 +95,25 @@ with gr.Blocks() as leaderboard:
69
  )
70
 
71
  for component in [verified, dataset, ipc, label]:
72
- component.change(fn=lambda v, d, i, l: gr.components.Dataframe(
73
- value=get_data(v, d, i, l),
 
 
 
 
 
 
 
 
 
 
74
  headers=COLUMN_NAMES,
75
  type="pandas",
76
  datatype=DATA_TITLE_TYPE,
77
  interactive=False,
78
  visible=True,
79
  max_height=500,
80
- ), inputs=[verified, dataset, ipc, label], outputs=board)
81
 
82
  citation_button = gr.Textbox(
83
  value=CITATION_BUTTON_TEXT,
 
4
  from constants import *
5
 
6
 
7
+ def get_data(verified, dataset, ipc, label_type, metric_weights=None):
8
+ if metric_weights is None:
9
+ metric_weights = [1.0 / len(METRICS) for _ in METRICS]
10
+ if not isinstance(label_type, list):
11
+ label_type = [label_type]
12
+
13
  data = pd.read_csv("data.csv")
14
  data["verified"] = data["verified"].apply(lambda x: bool(x))
15
  data["dataset"] = data["dataset"].apply(lambda x: DATASET_LIST[x])
 
19
  data = data[data["verified"] == verified]
20
  data = data[data["dataset"] == dataset]
21
  data = data[data["ipc"] == ipc]
22
+ data = data[data["label_type"].apply(lambda x: x in label_type)]
23
+
24
+ # create a new column for the score
25
+ data["score"] = data[METRICS[0].lower()] * 0.0
26
+ for i, metric in enumerate(METRICS):
27
+ data["score"] += data[metric.lower()] * metric_weights[i]
28
  data = data.sort_values(by="score", ascending=False)
29
+ data["ranking"] = range(1, len(data) + 1)
30
 
31
  # formatting
32
  data["method"] = "[" + data["method"] + "](" + data["method_reference"] + ")"
33
  data["verified"] = data["verified"].apply(lambda x: "✅" if x else "")
34
+ data = data.drop(columns=["method_reference", "dataset", "ipc"])
35
+ data = data[['ranking', 'method', 'verified', 'date', 'label_type', 'hlr', 'ior', 'score']]
36
  if label_type == "Hard Label":
37
+ data = data.rename(columns={"ranking": "Ranking", "method": "Method", "date": "Date", "label_type": "Label Type", "hlr": "HLR↓", "ior": "IOR↑", "score": "Score", "verified": "Verified"})
38
  else:
39
+ data = data.rename(columns={"ranking": "Ranking", "method": "Method", "date": "Date", "label_type": "Label Type", "hlr": "HLR↓", "ior": "IOR↑", "score": "Score", "verified": "Verified"})
40
  return data
41
 
42
 
 
62
  interactive=True,
63
  info=IPC_INFO
64
  )
65
+ label = gr.CheckboxGroup(
66
  label="Label Type",
67
  choices=LABEL_TYPE_LIST,
68
+ value=LABEL_TYPE_LIST,
69
+ info=LABEL_TYPE_INFO,
70
  interactive=True,
 
71
  )
72
 
73
+ with gr.Accordion("Adjust Score Weights", open=False):
74
+ gr.Markdown(WEIGHT_ADJUSTMENT_INTRODUCTION, latex_delimiters=[
75
+ {'left': '$$', 'right': '$$', 'display': True},
76
+ {'left': '$', 'right': '$', 'display': False},
77
+ {'left': '\\(', 'right': '\\)', 'display': False},
78
+ {'left': '\\[', 'right': '\\]', 'display': True}
79
+ ])
80
+ metric_sliders = []
81
+ for metric in METRICS:
82
+ metric_sliders.append(gr.Slider(label=f"Weight for {metric}", minimum=0.0, maximum=1.0, value=0.5, interactive=True))
83
+ adjust_btn = gr.Button("Adjust Weights")
84
+
85
+
86
+ metric_weights = [s.value for s in metric_sliders]
87
  board = gr.components.Dataframe(
88
+ value=get_data(verified.value, dataset.value, ipc.value, label.value, metric_weights),
89
  headers=COLUMN_NAMES,
90
  type="pandas",
91
  datatype=DATA_TITLE_TYPE,
 
95
  )
96
 
97
  for component in [verified, dataset, ipc, label]:
98
+ component.change(lambda v, d, i, l, *m: gr.components.Dataframe(
99
+ value=get_data(v, d, i, l, [s for s in m]),
100
+ headers=COLUMN_NAMES,
101
+ type="pandas",
102
+ datatype=DATA_TITLE_TYPE,
103
+ interactive=False,
104
+ visible=True,
105
+ max_height=500,
106
+ ), inputs=[verified, dataset, ipc, label] + metric_sliders, outputs=board)
107
+
108
+ adjust_btn.click(fn=lambda v, d, i, l, *m: gr.components.Dataframe(
109
+ value=get_data(v, d, i, l, [s for s in m]),
110
  headers=COLUMN_NAMES,
111
  type="pandas",
112
  datatype=DATA_TITLE_TYPE,
113
  interactive=False,
114
  visible=True,
115
  max_height=500,
116
+ ), inputs=[verified, dataset, ipc, label] + metric_sliders, outputs=board)
117
 
118
  citation_button = gr.Textbox(
119
  value=CITATION_BUTTON_TEXT,