Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,108 +1,33 @@
|
|
1 |
import os, glob
|
2 |
-
import json
|
3 |
-
from datetime import datetime, timezone
|
4 |
-
from dataclasses import dataclass
|
5 |
-
from datasets import load_dataset, Dataset
|
6 |
import pandas as pd
|
7 |
import gradio as gr
|
8 |
-
from
|
9 |
-
from
|
10 |
|
11 |
OWNER = "AIEnergyScore"
|
12 |
-
COMPUTE_SPACE = f"{OWNER}/launch-computation-example"
|
13 |
TOKEN = os.environ.get("DEBUG")
|
14 |
API = HfApi(token=TOKEN)
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
name: str
|
32 |
-
display_name: str = ""
|
33 |
-
symbol: str = "" # emoji
|
34 |
-
|
35 |
-
def start_compute_space():
|
36 |
-
API.restart_space(COMPUTE_SPACE)
|
37 |
-
gr.Info(f"Okay! {COMPUTE_SPACE} should be running now!")
|
38 |
-
|
39 |
-
def get_model_size(model_info: ModelInfo):
|
40 |
-
"""Gets the model size from the configuration, or the model name if the configuration does not contain the information."""
|
41 |
-
try:
|
42 |
-
model_size = round(model_info.safetensors["total"] / 1e9, 3)
|
43 |
-
except (AttributeError, TypeError):
|
44 |
-
return 0 # Unknown model sizes are indicated as 0
|
45 |
-
return model_size
|
46 |
-
|
47 |
-
def add_docker_eval(zip_file):
|
48 |
-
new_fid_list = zip_file.split("/")
|
49 |
-
new_fid = new_fid_list[-1]
|
50 |
-
if new_fid.endswith('.zip'):
|
51 |
-
API.upload_file(
|
52 |
-
path_or_fileobj=zip_file,
|
53 |
-
repo_id="AIEnergyScore/tested_proprietary_models",
|
54 |
-
path_in_repo='submitted_models/' + new_fid,
|
55 |
-
repo_type="dataset",
|
56 |
-
commit_message="Adding logs via submission Space.",
|
57 |
-
token=TOKEN
|
58 |
-
)
|
59 |
-
gr.Info('Uploaded logs to dataset! We will validate their validity and add them to the next version of the leaderboard.')
|
60 |
-
else:
|
61 |
-
gr.Info('You can only upload .zip files here!')
|
62 |
-
|
63 |
-
def add_new_eval(repo_id: str, task: str):
|
64 |
-
model_owner = repo_id.split("/")[0]
|
65 |
-
model_name = repo_id.split("/")[1]
|
66 |
-
current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
67 |
-
requests = load_dataset("AIEnergyScore/requests_debug", split="test", token=TOKEN)
|
68 |
-
requests_dset = requests.to_pandas()
|
69 |
-
model_list = requests_dset[requests_dset['status'] == 'COMPLETED']['model'].tolist()
|
70 |
-
task_models = list(API.list_models(filter=task_mappings[task]))
|
71 |
-
task_model_names = [m.id for m in task_models]
|
72 |
-
if repo_id in model_list:
|
73 |
-
gr.Info('This model has already been run!')
|
74 |
-
elif repo_id not in task_model_names:
|
75 |
-
gr.Info("This model isn't compatible with the chosen task! Pick a different model-task combination")
|
76 |
-
else:
|
77 |
-
try:
|
78 |
-
model_info = API.model_info(repo_id=repo_id)
|
79 |
-
model_size = get_model_size(model_info=model_info)
|
80 |
-
likes = model_info.likes
|
81 |
-
except Exception:
|
82 |
-
gr.Info("Could not find information for model %s" % (model_name))
|
83 |
-
model_size = None
|
84 |
-
likes = None
|
85 |
-
|
86 |
-
gr.Info("Adding request")
|
87 |
-
request_dict = {
|
88 |
-
"model": repo_id,
|
89 |
-
"status": "PENDING",
|
90 |
-
"submitted_time": pd.to_datetime(current_time),
|
91 |
-
"task": task_mappings[task],
|
92 |
-
"likes": likes,
|
93 |
-
"params": model_size,
|
94 |
-
"leaderboard_version": "v0",
|
95 |
-
}
|
96 |
-
print("Writing out request file to dataset")
|
97 |
-
df_request_dict = pd.DataFrame([request_dict])
|
98 |
-
print(df_request_dict)
|
99 |
-
df_final = pd.concat([requests_dset, df_request_dict], ignore_index=True)
|
100 |
-
updated_dset = Dataset.from_pandas(df_final)
|
101 |
-
updated_dset.push_to_hub("AIEnergyScore/requests_debug", split="test", token=TOKEN)
|
102 |
-
gr.Info("Starting compute space at %s " % COMPUTE_SPACE)
|
103 |
-
return start_compute_space()
|
104 |
|
105 |
def print_existing_models():
|
|
|
|
|
|
|
106 |
requests = load_dataset("AIEnergyScore/requests_debug", split="test", token=TOKEN)
|
107 |
requests_dset = requests.to_pandas()
|
108 |
model_df = requests_dset[['model', 'status']]
|
@@ -116,23 +41,14 @@ def highlight_cols(x):
|
|
116 |
df[df['status'] == 'FAILED'] = 'color: red'
|
117 |
return df
|
118 |
|
119 |
-
#
|
120 |
existing_models = print_existing_models()
|
121 |
formatted_df = existing_models.style.apply(highlight_cols, axis=None)
|
122 |
|
123 |
-
def get_leaderboard_models():
|
124 |
-
path = r'leaderboard_v0_data/energy'
|
125 |
-
filenames = glob.glob(path + "/*.csv")
|
126 |
-
data = []
|
127 |
-
for filename in filenames:
|
128 |
-
data.append(pd.read_csv(filename))
|
129 |
-
# Return an empty dataframe with expected columns if no files are found
|
130 |
-
if not data:
|
131 |
-
return pd.DataFrame(columns=['model', 'task'])
|
132 |
-
leaderboard_data = pd.concat(data, ignore_index=True)
|
133 |
-
return leaderboard_data[['model', 'task']]
|
134 |
-
|
135 |
def get_zip_data_link():
|
|
|
|
|
|
|
136 |
return (
|
137 |
'<a href="https://example.com/download.zip" '
|
138 |
'style="text-decoration: none; font-weight: bold; font-size: 1.1em; '
|
@@ -153,7 +69,7 @@ with gr.Blocks() as demo:
|
|
153 |
/* Center the subtitle text */
|
154 |
.centered-subtitle {
|
155 |
text-align: center;
|
156 |
-
font-size: 1.
|
157 |
margin-bottom: 20px;
|
158 |
}
|
159 |
/* Full width container for matching widget edges */
|
@@ -163,8 +79,13 @@ with gr.Blocks() as demo:
|
|
163 |
</style>
|
164 |
''')
|
165 |
|
166 |
-
# --- Header Links
|
167 |
with gr.Row(elem_classes="header-links"):
|
|
|
|
|
|
|
|
|
|
|
168 |
submission_link = gr.HTML(
|
169 |
'<a href="https://huggingface.co/spaces/AIEnergyScore/submission_portal" '
|
170 |
'style="text-decoration: none; font-weight: bold; font-size: 1.1em; '
|
@@ -192,61 +113,23 @@ with gr.Blocks() as demo:
|
|
192 |
'color: black; font-family: \'Inter\', sans-serif;">Community</a>'
|
193 |
)
|
194 |
|
195 |
-
# --- Logo (
|
196 |
gr.HTML('''
|
197 |
-
<div style="margin-top:
|
198 |
<img src="https://huggingface.co/spaces/AIEnergyScore/Leaderboard/resolve/main/logo.png"
|
199 |
alt="Logo"
|
200 |
-
style="
|
201 |
</div>
|
202 |
''')
|
203 |
|
204 |
-
# --- Subtitle
|
205 |
-
gr.Markdown('<p class="centered-subtitle">Welcome to the AI Energy Score Leaderboard.
|
206 |
|
207 |
-
# ---
|
208 |
with gr.Column(elem_classes="full-width"):
|
209 |
-
with gr.
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
label="Choose a benchmark task",
|
214 |
-
value='Text Generation',
|
215 |
-
multiselect=False,
|
216 |
-
interactive=True,
|
217 |
-
)
|
218 |
-
with gr.Column():
|
219 |
-
model_name_textbox = gr.Textbox(label="Model name (user_name/model_name)")
|
220 |
-
|
221 |
-
with gr.Row():
|
222 |
-
with gr.Column():
|
223 |
-
submit_button = gr.Button("Submit for Analysis")
|
224 |
-
submission_result = gr.Markdown()
|
225 |
-
submit_button.click(
|
226 |
-
fn=add_new_eval,
|
227 |
-
inputs=[model_name_textbox, task],
|
228 |
-
outputs=submission_result,
|
229 |
-
)
|
230 |
-
|
231 |
-
# --- Docker Log Submission (Simplified) ---
|
232 |
-
with gr.Accordion("Submit log files from a Docker run:", open=False):
|
233 |
-
gr.Markdown("""
|
234 |
-
**⚠️ Warning: By uploading the zip file, you confirm that you have read and agree to the following terms:**
|
235 |
-
|
236 |
-
- **Public Data Sharing:** You consent to the public sharing of the energy performance data derived from your submission. No additional information related to this model, including proprietary configurations, will be disclosed.
|
237 |
-
- **Data Integrity:** You certify that the log files submitted are accurate, unaltered, and generated directly from testing your model as per the specified benchmarking procedures.
|
238 |
-
- **Model Representation:** You affirm that the model tested and submitted is representative of the production-level version, including its level of quantization and any other relevant characteristics impacting energy efficiency and performance.
|
239 |
-
""")
|
240 |
-
file_output = gr.File(visible=False)
|
241 |
-
u = gr.UploadButton("Upload a zip file with logs", file_count="single", interactive=True)
|
242 |
-
u.upload(add_docker_eval, u, file_output)
|
243 |
-
|
244 |
-
# --- Leaderboard and Recent Models Accordions ---
|
245 |
-
with gr.Row():
|
246 |
-
with gr.Column():
|
247 |
-
with gr.Accordion("Models that are in the latest leaderboard version:", open=False, visible=False):
|
248 |
-
gr.Dataframe(get_leaderboard_models(), elem_classes="full-width")
|
249 |
-
with gr.Accordion("Models that have been benchmarked recently:", open=False, visible=False):
|
250 |
-
gr.Dataframe(formatted_df, elem_classes="full-width")
|
251 |
|
252 |
-
demo.launch()
|
|
|
1 |
import os, glob
|
|
|
|
|
|
|
|
|
2 |
import pandas as pd
|
3 |
import gradio as gr
|
4 |
+
from datasets import load_dataset
|
5 |
+
from huggingface_hub import HfApi
|
6 |
|
7 |
OWNER = "AIEnergyScore"
|
|
|
8 |
TOKEN = os.environ.get("DEBUG")
|
9 |
API = HfApi(token=TOKEN)
|
10 |
|
11 |
+
def get_leaderboard_models():
|
12 |
+
"""
|
13 |
+
Reads CSV files from the leaderboard directory and returns a DataFrame
|
14 |
+
containing the 'model' and 'task' columns.
|
15 |
+
If no CSV files are found, returns an empty DataFrame with those columns.
|
16 |
+
"""
|
17 |
+
path = r'leaderboard_v0_data/energy'
|
18 |
+
filenames = glob.glob(os.path.join(path, "*.csv"))
|
19 |
+
data = []
|
20 |
+
for filename in filenames:
|
21 |
+
data.append(pd.read_csv(filename))
|
22 |
+
if not data:
|
23 |
+
return pd.DataFrame(columns=['model', 'task'])
|
24 |
+
leaderboard_data = pd.concat(data, ignore_index=True)
|
25 |
+
return leaderboard_data[['model', 'task']]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def print_existing_models():
|
28 |
+
"""
|
29 |
+
Loads a dataset of requests and returns the models that have been benchmarked.
|
30 |
+
"""
|
31 |
requests = load_dataset("AIEnergyScore/requests_debug", split="test", token=TOKEN)
|
32 |
requests_dset = requests.to_pandas()
|
33 |
model_df = requests_dset[['model', 'status']]
|
|
|
41 |
df[df['status'] == 'FAILED'] = 'color: red'
|
42 |
return df
|
43 |
|
44 |
+
# Apply styling to the recently benchmarked models table.
|
45 |
existing_models = print_existing_models()
|
46 |
formatted_df = existing_models.style.apply(highlight_cols, axis=None)
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
def get_zip_data_link():
|
49 |
+
"""
|
50 |
+
Returns an HTML link for downloading logs.
|
51 |
+
"""
|
52 |
return (
|
53 |
'<a href="https://example.com/download.zip" '
|
54 |
'style="text-decoration: none; font-weight: bold; font-size: 1.1em; '
|
|
|
69 |
/* Center the subtitle text */
|
70 |
.centered-subtitle {
|
71 |
text-align: center;
|
72 |
+
font-size: 1.4em;
|
73 |
margin-bottom: 20px;
|
74 |
}
|
75 |
/* Full width container for matching widget edges */
|
|
|
79 |
</style>
|
80 |
''')
|
81 |
|
82 |
+
# --- Header Links ---
|
83 |
with gr.Row(elem_classes="header-links"):
|
84 |
+
leaderboard_link = gr.HTML(
|
85 |
+
'<a href="https://huggingface.co/spaces/AIEnergyScore/Leaderboard" '
|
86 |
+
'style="text-decoration: none; font-weight: bold; font-size: 1.1em; '
|
87 |
+
'color: black; font-family: \'Inter\', sans-serif;">Leaderboard</a>'
|
88 |
+
)
|
89 |
submission_link = gr.HTML(
|
90 |
'<a href="https://huggingface.co/spaces/AIEnergyScore/submission_portal" '
|
91 |
'style="text-decoration: none; font-weight: bold; font-size: 1.1em; '
|
|
|
113 |
'color: black; font-family: \'Inter\', sans-serif;">Community</a>'
|
114 |
)
|
115 |
|
116 |
+
# --- Logo (Centered) ---
|
117 |
gr.HTML('''
|
118 |
+
<div style="text-align: center; margin-top: 20px;">
|
119 |
<img src="https://huggingface.co/spaces/AIEnergyScore/Leaderboard/resolve/main/logo.png"
|
120 |
alt="Logo"
|
121 |
+
style="max-width: 500px; height: auto;">
|
122 |
</div>
|
123 |
''')
|
124 |
|
125 |
+
# --- Centered Subtitle ---
|
126 |
+
gr.Markdown('<p class="centered-subtitle">Welcome to the AI Energy Score Leaderboard. Explore the top-performing models below.</p>')
|
127 |
|
128 |
+
# --- Leaderboard Tables ---
|
129 |
with gr.Column(elem_classes="full-width"):
|
130 |
+
with gr.Accordion("Latest Leaderboard", open=True):
|
131 |
+
gr.Dataframe(get_leaderboard_models(), elem_classes="full-width")
|
132 |
+
with gr.Accordion("Recently Benchmarked Models", open=False):
|
133 |
+
gr.Dataframe(formatted_df, elem_classes="full-width")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
+
demo.launch()
|