bgamazay commited on
Commit
49e7f66
·
verified ·
1 Parent(s): 1ff6e80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import pandas as pd
3
  import os
4
  import zipfile
 
5
 
6
  CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
7
  CITATION_BUTTON_TEXT = r"""@misc{aienergyscore-leaderboard,
@@ -105,6 +106,15 @@ def zip_csv_files():
105
  zipf.write(filepath, arcname=filename)
106
  return zip_filename
107
 
 
 
 
 
 
 
 
 
 
108
  # --- Modified functions to include a sort_order parameter ---
109
  def get_model_names_html(task, sort_order="High to Low"):
110
  df = pd.read_csv('data/energy/' + task)
@@ -213,17 +223,11 @@ with demo:
213
  ### Welcome to the leaderboard for the [AI Energy Score Project!](https://huggingface.co/AIEnergyScore) — Select different tasks to see scored models."""
214
  )
215
 
216
- # Header links (using a row of components, including a Download Data button)
217
  with gr.Row():
218
  submission_link = gr.HTML('<a href="https://huggingface.co/spaces/AIEnergyScore/submission_portal" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">Submission Portal</a>')
219
  label_link = gr.HTML('<a href="https://huggingface.co/spaces/AIEnergyScore/Label" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">Label Generator</a>')
220
- download_button = gr.FileDownload(
221
- value=zip_csv_files(),
222
- file_name="data.zip",
223
- label="Download Data",
224
- variant="link",
225
- style={"margin": "0 15px", "font-weight": "bold", "font-size": "1.1em"}
226
- )
227
  faq_link = gr.HTML('<a href="https://huggingface.github.io/AIEnergyScore/#faq" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">FAQ</a>')
228
  documentation_link = gr.HTML('<a href="https://huggingface.github.io/AIEnergyScore/#documentation" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">Documentation</a>')
229
  community_link = gr.HTML('<a href="https://huggingface.co/spaces/AIEnergyScore/README/discussions" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">Community</a>')
 
2
  import pandas as pd
3
  import os
4
  import zipfile
5
+ import base64
6
 
7
  CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
8
  CITATION_BUTTON_TEXT = r"""@misc{aienergyscore-leaderboard,
 
106
  zipf.write(filepath, arcname=filename)
107
  return zip_filename
108
 
109
+ def get_zip_data_link():
110
+ """Creates a data URI download link for the ZIP file."""
111
+ zip_filename = zip_csv_files()
112
+ with open(zip_filename, "rb") as f:
113
+ data = f.read()
114
+ b64 = base64.b64encode(data).decode()
115
+ href = f'<a href="data:application/zip;base64,{b64}" download="data.zip" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">Download Data</a>'
116
+ return href
117
+
118
  # --- Modified functions to include a sort_order parameter ---
119
  def get_model_names_html(task, sort_order="High to Low"):
120
  df = pd.read_csv('data/energy/' + task)
 
223
  ### Welcome to the leaderboard for the [AI Energy Score Project!](https://huggingface.co/AIEnergyScore) — Select different tasks to see scored models."""
224
  )
225
 
226
+ # Header links (using a row of components, including a Download Data link)
227
  with gr.Row():
228
  submission_link = gr.HTML('<a href="https://huggingface.co/spaces/AIEnergyScore/submission_portal" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">Submission Portal</a>')
229
  label_link = gr.HTML('<a href="https://huggingface.co/spaces/AIEnergyScore/Label" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">Label Generator</a>')
230
+ download_link = gr.HTML(get_zip_data_link())
 
 
 
 
 
 
231
  faq_link = gr.HTML('<a href="https://huggingface.github.io/AIEnergyScore/#faq" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">FAQ</a>')
232
  documentation_link = gr.HTML('<a href="https://huggingface.github.io/AIEnergyScore/#documentation" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">Documentation</a>')
233
  community_link = gr.HTML('<a href="https://huggingface.co/spaces/AIEnergyScore/README/discussions" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">Community</a>')