Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,12 +26,6 @@ tasks = [
|
|
| 26 |
]
|
| 27 |
|
| 28 |
def format_stars(score):
|
| 29 |
-
"""
|
| 30 |
-
Convert the energy_score (assumed to be an integer from 1 to 5)
|
| 31 |
-
into that many star characters wrapped in a span styled with color #3fa45bff
|
| 32 |
-
and with a font size increased to 2em.
|
| 33 |
-
The '!important' rules force the styling immediately.
|
| 34 |
-
"""
|
| 35 |
try:
|
| 36 |
score_int = int(score)
|
| 37 |
except Exception:
|
|
@@ -39,47 +33,27 @@ def format_stars(score):
|
|
| 39 |
return f'<span style="color: #3fa45bff !important; font-size:2em !important;">{"★" * score_int}</span>'
|
| 40 |
|
| 41 |
def make_link(mname):
|
| 42 |
-
"""
|
| 43 |
-
Create a markdown link for the model.
|
| 44 |
-
For example, if mname is "org/model", display "model" and link to its HF page.
|
| 45 |
-
"""
|
| 46 |
parts = str(mname).split('/')
|
| 47 |
display_name = parts[1] if len(parts) > 1 else mname
|
| 48 |
return f'[{display_name}](https://huggingface.co/{mname})'
|
| 49 |
|
| 50 |
def get_plots(task):
|
| 51 |
-
"""
|
| 52 |
-
Read the energy CSV for a given task and return a Plotly scatter plot.
|
| 53 |
-
The x-axis uses the 'total_gpu_energy' column (rounded to 4 decimals) and
|
| 54 |
-
the y-axis displays only the model name (extracted from the 'model' column).
|
| 55 |
-
"""
|
| 56 |
df = pd.read_csv('data/energy/' + task)
|
| 57 |
-
# If an extra unnamed index column exists, drop it.
|
| 58 |
if df.columns[0].startswith("Unnamed:"):
|
| 59 |
df = df.iloc[:, 1:]
|
| 60 |
df['energy_score'] = df['energy_score'].astype(int)
|
| 61 |
-
# Use the correct column: "total_gpu_energy"
|
| 62 |
-
df['GPU Energy (Wh)'] = df['total_gpu_energy'].round(4)
|
| 63 |
-
# Create a column that displays only the model name (the part after '/')
|
| 64 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
| 65 |
|
| 66 |
-
|
| 67 |
-
color_map = {
|
| 68 |
-
1: "red",
|
| 69 |
-
2: "orange",
|
| 70 |
-
3: "yellow",
|
| 71 |
-
4: "lightgreen",
|
| 72 |
-
5: "green"
|
| 73 |
-
}
|
| 74 |
|
| 75 |
fig = px.scatter(
|
| 76 |
df,
|
| 77 |
-
x="
|
| 78 |
-
y="Display Model",
|
|
|
|
| 79 |
custom_data=['energy_score'],
|
| 80 |
height=500,
|
| 81 |
width=800,
|
| 82 |
-
color="energy_score",
|
| 83 |
color_discrete_map=color_map
|
| 84 |
)
|
| 85 |
fig.update_traces(
|
|
@@ -93,36 +67,26 @@ def get_plots(task):
|
|
| 93 |
return fig
|
| 94 |
|
| 95 |
def get_all_plots():
|
| 96 |
-
"""
|
| 97 |
-
Combine data from all tasks and return a scatter plot.
|
| 98 |
-
Duplicate models are dropped.
|
| 99 |
-
"""
|
| 100 |
all_df = pd.DataFrame()
|
| 101 |
for task in tasks:
|
| 102 |
df = pd.read_csv('data/energy/' + task)
|
| 103 |
if df.columns[0].startswith("Unnamed:"):
|
| 104 |
df = df.iloc[:, 1:]
|
| 105 |
df['energy_score'] = df['energy_score'].astype(int)
|
| 106 |
-
df['GPU Energy (Wh)'] = df['total_gpu_energy'].round(4)
|
| 107 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
| 108 |
all_df = pd.concat([all_df, df], ignore_index=True)
|
| 109 |
all_df = all_df.drop_duplicates(subset=['model'])
|
| 110 |
|
| 111 |
-
color_map = {
|
| 112 |
-
|
| 113 |
-
2: "orange",
|
| 114 |
-
3: "yellow",
|
| 115 |
-
4: "lightgreen",
|
| 116 |
-
5: "green"
|
| 117 |
-
}
|
| 118 |
fig = px.scatter(
|
| 119 |
all_df,
|
| 120 |
-
x="
|
| 121 |
y="Display Model",
|
|
|
|
| 122 |
custom_data=['energy_score'],
|
| 123 |
height=500,
|
| 124 |
width=800,
|
| 125 |
-
color="energy_score",
|
| 126 |
color_discrete_map=color_map
|
| 127 |
)
|
| 128 |
fig.update_traces(
|
|
|
|
| 26 |
]
|
| 27 |
|
| 28 |
def format_stars(score):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
try:
|
| 30 |
score_int = int(score)
|
| 31 |
except Exception:
|
|
|
|
| 33 |
return f'<span style="color: #3fa45bff !important; font-size:2em !important;">{"★" * score_int}</span>'
|
| 34 |
|
| 35 |
def make_link(mname):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
parts = str(mname).split('/')
|
| 37 |
display_name = parts[1] if len(parts) > 1 else mname
|
| 38 |
return f'[{display_name}](https://huggingface.co/{mname})'
|
| 39 |
|
| 40 |
def get_plots(task):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
df = pd.read_csv('data/energy/' + task)
|
|
|
|
| 42 |
if df.columns[0].startswith("Unnamed:"):
|
| 43 |
df = df.iloc[:, 1:]
|
| 44 |
df['energy_score'] = df['energy_score'].astype(int)
|
|
|
|
|
|
|
|
|
|
| 45 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
| 46 |
|
| 47 |
+
color_map = {1: "red", 2: "orange", 3: "yellow", 4: "lightgreen", 5: "green"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
fig = px.scatter(
|
| 50 |
df,
|
| 51 |
+
x="total_gpu_energy", # Ensure correct column for x-axis
|
| 52 |
+
y="Display Model", # Keep model name for y-axis
|
| 53 |
+
color="energy_score", # Ensure correct column for point color
|
| 54 |
custom_data=['energy_score'],
|
| 55 |
height=500,
|
| 56 |
width=800,
|
|
|
|
| 57 |
color_discrete_map=color_map
|
| 58 |
)
|
| 59 |
fig.update_traces(
|
|
|
|
| 67 |
return fig
|
| 68 |
|
| 69 |
def get_all_plots():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
all_df = pd.DataFrame()
|
| 71 |
for task in tasks:
|
| 72 |
df = pd.read_csv('data/energy/' + task)
|
| 73 |
if df.columns[0].startswith("Unnamed:"):
|
| 74 |
df = df.iloc[:, 1:]
|
| 75 |
df['energy_score'] = df['energy_score'].astype(int)
|
|
|
|
| 76 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
| 77 |
all_df = pd.concat([all_df, df], ignore_index=True)
|
| 78 |
all_df = all_df.drop_duplicates(subset=['model'])
|
| 79 |
|
| 80 |
+
color_map = {1: "red", 2: "orange", 3: "yellow", 4: "lightgreen", 5: "green"}
|
| 81 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
fig = px.scatter(
|
| 83 |
all_df,
|
| 84 |
+
x="total_gpu_energy", # Ensure correct column for x-axis
|
| 85 |
y="Display Model",
|
| 86 |
+
color="energy_score", # Ensure correct column for point color
|
| 87 |
custom_data=['energy_score'],
|
| 88 |
height=500,
|
| 89 |
width=800,
|
|
|
|
| 90 |
color_discrete_map=color_map
|
| 91 |
)
|
| 92 |
fig.update_traces(
|