Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
0b51aac
1
Parent(s):
7c92464
feat: add download button
Browse files
app.py
CHANGED
|
@@ -10,7 +10,18 @@ def restart_space():
|
|
| 10 |
HF_API.restart_space(repo_id=HF_LEADERBOARD)
|
| 11 |
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
if __name__ == "__main__":
|
|
@@ -33,6 +44,10 @@ if __name__ == "__main__":
|
|
| 33 |
column_widths=["20%"],
|
| 34 |
wrap=True,
|
| 35 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
with gr.Tab("Unvalidated"):
|
| 38 |
unverified_table = gr.Dataframe(
|
|
@@ -42,9 +57,24 @@ if __name__ == "__main__":
|
|
| 42 |
column_widths=["20%"],
|
| 43 |
wrap=True,
|
| 44 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
# create a Gradio event listener that runs when the page is loaded to populate the dataframe
|
| 46 |
demo.load(generate_leaderboard_df, inputs=None, outputs=[verified_table, unverified_table])
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
refresh_button = gr.Button("Refresh")
|
| 49 |
refresh_button.click(
|
| 50 |
refresh,
|
|
|
|
| 10 |
HF_API.restart_space(repo_id=HF_LEADERBOARD)
|
| 11 |
|
| 12 |
|
| 13 |
+
def download_leaderboard(type):
|
| 14 |
+
verified_lb, unverified_lb = generate_leaderboard_df()
|
| 15 |
+
if type == "verified":
|
| 16 |
+
df_to_download = verified_lb
|
| 17 |
+
if type == "unverified":
|
| 18 |
+
df_to_download = unverified_lb
|
| 19 |
|
| 20 |
+
path = f"data/{type}_leaderboard.csv"
|
| 21 |
+
if os.path.exists(path):
|
| 22 |
+
os.remove(path)
|
| 23 |
+
df_to_download.to_csv(path, index=False)
|
| 24 |
+
return path
|
| 25 |
|
| 26 |
|
| 27 |
if __name__ == "__main__":
|
|
|
|
| 44 |
column_widths=["20%"],
|
| 45 |
wrap=True,
|
| 46 |
)
|
| 47 |
+
verified_download = gr.DownloadButton(
|
| 48 |
+
label="Download Leaderboard",
|
| 49 |
+
elem_id="download-verified-lb",
|
| 50 |
+
)
|
| 51 |
|
| 52 |
with gr.Tab("Unvalidated"):
|
| 53 |
unverified_table = gr.Dataframe(
|
|
|
|
| 57 |
column_widths=["20%"],
|
| 58 |
wrap=True,
|
| 59 |
)
|
| 60 |
+
unverified_download = gr.DownloadButton(
|
| 61 |
+
label="Download Leaderboard",
|
| 62 |
+
elem_id="download-unverified-lb",
|
| 63 |
+
)
|
| 64 |
# create a Gradio event listener that runs when the page is loaded to populate the dataframe
|
| 65 |
demo.load(generate_leaderboard_df, inputs=None, outputs=[verified_table, unverified_table])
|
| 66 |
|
| 67 |
+
verified_download.click(
|
| 68 |
+
download_leaderboard,
|
| 69 |
+
inputs=[gr.Textbox(value="verified", visible=False)],
|
| 70 |
+
outputs=[verified_download]
|
| 71 |
+
)
|
| 72 |
+
unverified_download.click(
|
| 73 |
+
download_leaderboard,
|
| 74 |
+
inputs=[gr.Textbox(value="unverified", visible=False)],
|
| 75 |
+
outputs=[unverified_download]
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
refresh_button = gr.Button("Refresh")
|
| 79 |
refresh_button.click(
|
| 80 |
refresh,
|