pquintero commited on
Commit
84fdef4
·
1 Parent(s): 6a1bc0f

dropdown with submission type updating example download

Browse files
Files changed (1) hide show
  1. app.py +53 -14
app.py CHANGED
@@ -4,7 +4,13 @@ import gradio as gr
4
  from gradio_leaderboard import Leaderboard
5
 
6
  from utils import fetch_hf_results, show_output_box
7
- from constants import ASSAY_LIST, ASSAY_RENAME, ASSAY_EMOJIS, ASSAY_DESCRIPTION
 
 
 
 
 
 
8
  from about import ABOUT_TEXT, FAQS
9
  from submit import make_submission
10
 
@@ -22,6 +28,17 @@ def format_leaderboard_table(df_results: pd.DataFrame, assay: str | None = None)
22
  return df.sort_values(by="spearman", ascending=False)
23
 
24
 
 
 
 
 
 
 
 
 
 
 
 
25
  def get_leaderboard_object(assay: str | None = None):
26
  filter_columns = ["model"]
27
  if assay is None:
@@ -29,7 +46,7 @@ def get_leaderboard_object(assay: str | None = None):
29
  # TODO how to sort filter columns alphabetically?
30
  Leaderboard(
31
  # TODO(Lood) check that this actually refreshes using the function
32
- value=format_leaderboard_table(df_results=fetch_hf_results(), assay=assay),
33
  datatype=["str", "str", "str", "number"],
34
  select_columns=["model", "property", "spearman", "spearman_cross_val"],
35
  search_columns=["model"],
@@ -90,18 +107,13 @@ with gr.Blocks() as demo:
90
  filename = gr.State(value=None)
91
  eval_state = gr.State(value=None)
92
  user_state = gr.State(value=None)
93
- anonymous_state = gr.State(value=False)
 
94
 
95
  login_button = gr.LoginButton(
96
  value="Sign in with Hugging Face to see account name"
97
  ) # Note(Lood): Is this mandatory?
98
 
99
- gr.DownloadButton(
100
- label="📥 Download example submission CSV",
101
- value="data/example-predictions.csv",
102
- variant="secondary",
103
- )
104
-
105
  with gr.Row():
106
  with gr.Column():
107
  username_input = gr.Textbox(
@@ -109,11 +121,17 @@ with gr.Blocks() as demo:
109
  placeholder="Enter your Hugging Face username",
110
  info="This will be displayed on the leaderboard.",
111
  )
112
-
113
- anonymous_checkbox = gr.Checkbox(
114
- label="Would you like to keep your submission anonymous?"
115
- ) # Can make this ticked by default
116
  with gr.Column():
 
 
 
 
 
 
 
 
 
 
117
  submission_file = gr.File(label="Submission CSV")
118
 
119
  # TODO(Lood): How do we get the username from the login button instead? Do we want this?
@@ -123,6 +141,27 @@ with gr.Blocks() as demo:
123
  outputs=user_state,
124
  )
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  submit_btn = gr.Button("Evaluate")
127
  message = gr.Textbox(label="Status", lines=1, visible=False)
128
  # help message
@@ -132,7 +171,7 @@ with gr.Blocks() as demo:
132
 
133
  submit_btn.click(
134
  make_submission,
135
- inputs=[submission_file, user_state, anonymous_state],
136
  outputs=[message],
137
  ).then(
138
  fn=show_output_box,
 
4
  from gradio_leaderboard import Leaderboard
5
 
6
  from utils import fetch_hf_results, show_output_box
7
+ from constants import (
8
+ ASSAY_LIST,
9
+ ASSAY_RENAME,
10
+ ASSAY_EMOJIS,
11
+ ASSAY_DESCRIPTION,
12
+ EXAMPLE_FILE_DICT,
13
+ )
14
  from about import ABOUT_TEXT, FAQS
15
  from submit import make_submission
16
 
 
28
  return df.sort_values(by="spearman", ascending=False)
29
 
30
 
31
+ # Cache the results to avoid multiple downloads
32
+ _cached_results = None
33
+
34
+
35
+ def get_cached_results():
36
+ global _cached_results
37
+ if _cached_results is None:
38
+ _cached_results = fetch_hf_results()
39
+ return _cached_results
40
+
41
+
42
  def get_leaderboard_object(assay: str | None = None):
43
  filter_columns = ["model"]
44
  if assay is None:
 
46
  # TODO how to sort filter columns alphabetically?
47
  Leaderboard(
48
  # TODO(Lood) check that this actually refreshes using the function
49
+ value=format_leaderboard_table(df_results=get_cached_results(), assay=assay),
50
  datatype=["str", "str", "str", "number"],
51
  select_columns=["model", "property", "spearman", "spearman_cross_val"],
52
  search_columns=["model"],
 
107
  filename = gr.State(value=None)
108
  eval_state = gr.State(value=None)
109
  user_state = gr.State(value=None)
110
+ submission_type_state = gr.State(value="GDPa1")
111
+ download_file_state = gr.State(value=EXAMPLE_FILE_DICT["GDPa1"])
112
 
113
  login_button = gr.LoginButton(
114
  value="Sign in with Hugging Face to see account name"
115
  ) # Note(Lood): Is this mandatory?
116
 
 
 
 
 
 
 
117
  with gr.Row():
118
  with gr.Column():
119
  username_input = gr.Textbox(
 
121
  placeholder="Enter your Hugging Face username",
122
  info="This will be displayed on the leaderboard.",
123
  )
 
 
 
 
124
  with gr.Column():
125
+ submission_type_dropdown = gr.Dropdown(
126
+ choices=["GDPa1", "GDPa1_cross_validation"],
127
+ value="GDPa1",
128
+ label="Submission Type",
129
+ )
130
+ download_button = gr.DownloadButton(
131
+ label="📥 Download example submission CSV",
132
+ value=EXAMPLE_FILE_DICT["GDPa1"],
133
+ variant="secondary",
134
+ )
135
  submission_file = gr.File(label="Submission CSV")
136
 
137
  # TODO(Lood): How do we get the username from the login button instead? Do we want this?
 
141
  outputs=user_state,
142
  )
143
 
144
+ def update_submission_type_and_file(submission_type):
145
+ download_file = EXAMPLE_FILE_DICT.get(
146
+ submission_type, EXAMPLE_FILE_DICT["GDPa1"]
147
+ )
148
+ return (
149
+ submission_type,
150
+ download_file,
151
+ gr.DownloadButton(
152
+ label="📥 Download example submission CSV",
153
+ value=download_file,
154
+ variant="secondary",
155
+ ),
156
+ )
157
+
158
+ # Update submission type state and download button when dropdown changes
159
+ submission_type_dropdown.change(
160
+ fn=update_submission_type_and_file,
161
+ inputs=submission_type_dropdown,
162
+ outputs=[submission_type_state, download_file_state, download_button],
163
+ )
164
+
165
  submit_btn = gr.Button("Evaluate")
166
  message = gr.Textbox(label="Status", lines=1, visible=False)
167
  # help message
 
171
 
172
  submit_btn.click(
173
  make_submission,
174
+ inputs=[submission_file, user_state, submission_type_state],
175
  outputs=[message],
176
  ).then(
177
  fn=show_output_box,