Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -52,8 +52,9 @@ def extract_link_text(html_link):
|
|
52 |
def generate_html_table_from_df(df):
|
53 |
"""
|
54 |
Given a dataframe with a numeric energy column (gpu_energy_numeric),
|
55 |
-
generate an HTML table with
|
56 |
- Model (the link, with a fixed width based on the longest model name)
|
|
|
57 |
- GPU Energy (Wh) plus a horizontal bar whose width is proportional
|
58 |
to the energy value relative to the maximum in the table.
|
59 |
- Score (displayed as stars)
|
@@ -70,6 +71,7 @@ def generate_html_table_from_df(df):
|
|
70 |
html = '<table style="width:100%; border-collapse: collapse; font-family: Inter, sans-serif;">'
|
71 |
html += '<thead><tr style="background-color: #f2f2f2;">'
|
72 |
html += '<th style="text-align: left; padding: 8px;" title="Model name with link to Hugging Face">Model</th>'
|
|
|
73 |
html += '<th style="text-align: left; padding: 8px;" title="GPU energy consumed in Watt-hours for 1,000 queries">GPU Energy (Wh)</th>'
|
74 |
html += '<th style="text-align: left; padding: 8px;" title="5 is most efficient, 1 is least. Relative energy efficiency score relative to other models in task/class at the time of leaderboard launch">Score</th>'
|
75 |
html += '</tr></thead>'
|
@@ -82,6 +84,7 @@ def generate_html_table_from_df(df):
|
|
82 |
bar_color = color_map.get(str(score_val), "gray")
|
83 |
html += '<tr>'
|
84 |
html += f'<td style="padding: 8px; width: {static_width}px;">{row["Model"]}</td>'
|
|
|
85 |
html += (
|
86 |
f'<td style="padding: 8px;">{energy_str}<br>'
|
87 |
f'<div style="background-color: {bar_color}; width: {bar_width:.1f}%; height: 10px;"></div></td>'
|
@@ -124,6 +127,8 @@ def get_model_names_html(task, sort_order="Low to High"):
|
|
124 |
df = df.iloc[:, 1:]
|
125 |
df['energy_score'] = df['energy_score'].astype(int)
|
126 |
df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
|
|
|
|
|
127 |
df['Model'] = df['model'].apply(make_link)
|
128 |
df['Score'] = df['energy_score'].apply(format_stars)
|
129 |
ascending = True if sort_order == "Low to High" else False
|
@@ -138,6 +143,8 @@ def get_all_model_names_html(sort_order="Low to High"):
|
|
138 |
df = df.iloc[:, 1:]
|
139 |
df['energy_score'] = df['energy_score'].astype(int)
|
140 |
df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
|
|
|
|
|
141 |
df['Model'] = df['model'].apply(make_link)
|
142 |
df['Score'] = df['energy_score'].apply(format_stars)
|
143 |
all_df = pd.concat([all_df, df], ignore_index=True)
|
@@ -154,6 +161,8 @@ def get_text_generation_model_names_html(model_class, sort_order="Low to High"):
|
|
154 |
df = df[df['class'] == model_class]
|
155 |
df['energy_score'] = df['energy_score'].astype(int)
|
156 |
df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
|
|
|
|
|
157 |
df['Model'] = df['model'].apply(make_link)
|
158 |
df['Score'] = df['energy_score'].apply(format_stars)
|
159 |
ascending = True if sort_order == "Low to High" else False
|
@@ -213,7 +222,7 @@ demo = gr.Blocks(css="""
|
|
213 |
text-overflow: ellipsis;
|
214 |
}
|
215 |
.table-container {
|
216 |
-
|
217 |
margin-left: auto;
|
218 |
margin-right: auto;
|
219 |
}
|
@@ -375,4 +384,4 @@ with demo:
|
|
375 |
)
|
376 |
gr.Markdown("Last updated: February 2025")
|
377 |
|
378 |
-
demo.launch()
|
|
|
52 |
def generate_html_table_from_df(df):
|
53 |
"""
|
54 |
Given a dataframe with a numeric energy column (gpu_energy_numeric),
|
55 |
+
generate an HTML table with four columns:
|
56 |
- Model (the link, with a fixed width based on the longest model name)
|
57 |
+
- Provider (extracted from the model field)
|
58 |
- GPU Energy (Wh) plus a horizontal bar whose width is proportional
|
59 |
to the energy value relative to the maximum in the table.
|
60 |
- Score (displayed as stars)
|
|
|
71 |
html = '<table style="width:100%; border-collapse: collapse; font-family: Inter, sans-serif;">'
|
72 |
html += '<thead><tr style="background-color: #f2f2f2;">'
|
73 |
html += '<th style="text-align: left; padding: 8px;" title="Model name with link to Hugging Face">Model</th>'
|
74 |
+
html += '<th style="text-align: left; padding: 8px;" title="AI Provider extracted from the model name">Provider</th>'
|
75 |
html += '<th style="text-align: left; padding: 8px;" title="GPU energy consumed in Watt-hours for 1,000 queries">GPU Energy (Wh)</th>'
|
76 |
html += '<th style="text-align: left; padding: 8px;" title="5 is most efficient, 1 is least. Relative energy efficiency score relative to other models in task/class at the time of leaderboard launch">Score</th>'
|
77 |
html += '</tr></thead>'
|
|
|
84 |
bar_color = color_map.get(str(score_val), "gray")
|
85 |
html += '<tr>'
|
86 |
html += f'<td style="padding: 8px; width: {static_width}px;">{row["Model"]}</td>'
|
87 |
+
html += f'<td style="padding: 8px;">{row["Provider"]}</td>'
|
88 |
html += (
|
89 |
f'<td style="padding: 8px;">{energy_str}<br>'
|
90 |
f'<div style="background-color: {bar_color}; width: {bar_width:.1f}%; height: 10px;"></div></td>'
|
|
|
127 |
df = df.iloc[:, 1:]
|
128 |
df['energy_score'] = df['energy_score'].astype(int)
|
129 |
df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
|
130 |
+
# Add the Provider column (text before the slash in the model field)
|
131 |
+
df['Provider'] = df['model'].apply(lambda x: str(x).split('/')[0])
|
132 |
df['Model'] = df['model'].apply(make_link)
|
133 |
df['Score'] = df['energy_score'].apply(format_stars)
|
134 |
ascending = True if sort_order == "Low to High" else False
|
|
|
143 |
df = df.iloc[:, 1:]
|
144 |
df['energy_score'] = df['energy_score'].astype(int)
|
145 |
df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
|
146 |
+
# Add the Provider column here as well.
|
147 |
+
df['Provider'] = df['model'].apply(lambda x: str(x).split('/')[0])
|
148 |
df['Model'] = df['model'].apply(make_link)
|
149 |
df['Score'] = df['energy_score'].apply(format_stars)
|
150 |
all_df = pd.concat([all_df, df], ignore_index=True)
|
|
|
161 |
df = df[df['class'] == model_class]
|
162 |
df['energy_score'] = df['energy_score'].astype(int)
|
163 |
df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
|
164 |
+
# Add the Provider column here as well.
|
165 |
+
df['Provider'] = df['model'].apply(lambda x: str(x).split('/')[0])
|
166 |
df['Model'] = df['model'].apply(make_link)
|
167 |
df['Score'] = df['energy_score'].apply(format_stars)
|
168 |
ascending = True if sort_order == "Low to High" else False
|
|
|
222 |
text-overflow: ellipsis;
|
223 |
}
|
224 |
.table-container {
|
225 |
+
width: 100%;
|
226 |
margin-left: auto;
|
227 |
margin-right: auto;
|
228 |
}
|
|
|
384 |
)
|
385 |
gr.Markdown("Last updated: February 2025")
|
386 |
|
387 |
+
demo.launch()
|