Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ def main():
|
|
10 |
st.sidebar.write("1. Select a model from the dropdown.")
|
11 |
st.sidebar.write("2. Review the label preview.")
|
12 |
st.sidebar.write("3. Download the label as a PNG.")
|
13 |
-
st.sidebar.markdown("[
|
14 |
|
15 |
# Read Data from CSV
|
16 |
try:
|
@@ -34,22 +34,22 @@ def main():
|
|
34 |
model_data = data_df[data_df["model"] == selected_model].iloc[0]
|
35 |
|
36 |
# Dynamically select the background image based on the score
|
37 |
-
try:
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
except FileNotFoundError:
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
except ValueError:
|
51 |
-
|
52 |
-
|
53 |
|
54 |
# Generate the label with text
|
55 |
generated_label = create_label(background, model_data)
|
|
|
10 |
st.sidebar.write("1. Select a model from the dropdown.")
|
11 |
st.sidebar.write("2. Review the label preview.")
|
12 |
st.sidebar.write("3. Download the label as a PNG.")
|
13 |
+
st.sidebar.markdown("[AI Energy Score Leaderboard](https://huggingface.co/spaces/AIEnergyScore/Leaderboard)")
|
14 |
|
15 |
# Read Data from CSV
|
16 |
try:
|
|
|
34 |
model_data = data_df[data_df["model"] == selected_model].iloc[0]
|
35 |
|
36 |
# Dynamically select the background image based on the score
|
37 |
+
try:
|
38 |
+
score = int(model_data["score"]) # Convert to int
|
39 |
+
background_path = f"{score}.png" # E.g., "1.png", "2.png"
|
40 |
+
background = Image.open(background_path).convert("RGBA")
|
41 |
+
|
42 |
+
# Proportional scaling to fit within the target size
|
43 |
+
target_size = (800, 600) # Maximum width and height
|
44 |
+
background.thumbnail(target_size, Image.ANTIALIAS)
|
45 |
+
|
46 |
+
except FileNotFoundError:
|
47 |
+
st.sidebar.error(f"Could not find background image '{score}.png'. Using default background.")
|
48 |
+
background = Image.open("default_background.png").convert("RGBA")
|
49 |
+
background.thumbnail(target_size, Image.ANTIALIAS) # Resize default image proportionally
|
50 |
+
except ValueError:
|
51 |
+
st.sidebar.error(f"Invalid score '{model_data['score']}'. Score must be an integer.")
|
52 |
+
return
|
53 |
|
54 |
# Generate the label with text
|
55 |
generated_label = create_label(background, model_data)
|