Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,18 +30,19 @@ def main():
|
|
| 30 |
|
| 31 |
# Dropdown for selecting a model
|
| 32 |
st.sidebar.write("### Instructions:")
|
| 33 |
-
st.sidebar.write("1. Select a model
|
| 34 |
model_options = data_df["model"].unique().tolist() # Get model options
|
| 35 |
selected_model = st.sidebar.selectbox(
|
| 36 |
-
"
|
| 37 |
) # Searchable dropdown
|
| 38 |
|
| 39 |
# Add step 2 instructions and move the Download button
|
| 40 |
-
st.sidebar.write("2.
|
| 41 |
|
| 42 |
-
#
|
| 43 |
model_data = data_df[data_df["model"] == selected_model].iloc[0]
|
| 44 |
|
|
|
|
| 45 |
try:
|
| 46 |
score = int(model_data["score"]) # Convert to int
|
| 47 |
background_path = f"{score}.png" # E.g., "1.png", "2.png"
|
|
@@ -71,7 +72,7 @@ def main():
|
|
| 71 |
img_buffer.seek(0)
|
| 72 |
|
| 73 |
st.sidebar.download_button(
|
| 74 |
-
label="Download Label
|
| 75 |
data=img_buffer,
|
| 76 |
file_name="AIEnergyScore.png",
|
| 77 |
mime="image/png"
|
|
@@ -81,45 +82,6 @@ def main():
|
|
| 81 |
st.sidebar.write("3. Share your label in technical reports, announcements, etc.")
|
| 82 |
st.sidebar.markdown("[AI Energy Score Leaderboard](https://huggingface.co/spaces/AIEnergyScore/Leaderboard)")
|
| 83 |
|
| 84 |
-
# Filter the data for the selected model
|
| 85 |
-
model_data = data_df[data_df["model"] == selected_model].iloc[0]
|
| 86 |
-
|
| 87 |
-
# Dynamically select the background image based on the score
|
| 88 |
-
try:
|
| 89 |
-
score = int(model_data["score"]) # Convert to int
|
| 90 |
-
background_path = f"{score}.png" # E.g., "1.png", "2.png"
|
| 91 |
-
background = Image.open(background_path).convert("RGBA")
|
| 92 |
-
|
| 93 |
-
# Proportional scaling to fit within the target size
|
| 94 |
-
target_size = (800, 600) # Maximum width and height
|
| 95 |
-
background.thumbnail(target_size, Image.Resampling.LANCZOS)
|
| 96 |
-
|
| 97 |
-
except FileNotFoundError:
|
| 98 |
-
st.sidebar.error(f"Could not find background image '{score}.png'. Using default background.")
|
| 99 |
-
background = Image.open("default_background.png").convert("RGBA")
|
| 100 |
-
background.thumbnail(target_size, Image.Resampling.LANCZOS) # Resize default image proportionally
|
| 101 |
-
except ValueError:
|
| 102 |
-
st.sidebar.error(f"Invalid score '{model_data['score']}'. Score must be an integer.")
|
| 103 |
-
return
|
| 104 |
-
|
| 105 |
-
# Generate the label with text
|
| 106 |
-
generated_label = create_label(background, model_data)
|
| 107 |
-
|
| 108 |
-
# Display the label
|
| 109 |
-
st.image(generated_label, caption="Generated Label Preview")
|
| 110 |
-
|
| 111 |
-
# Download button for the label
|
| 112 |
-
img_buffer = io.BytesIO()
|
| 113 |
-
generated_label.save(img_buffer, format="PNG")
|
| 114 |
-
img_buffer.seek(0)
|
| 115 |
-
|
| 116 |
-
st.sidebar.download_button(
|
| 117 |
-
label="Download Label as PNG",
|
| 118 |
-
data=img_buffer,
|
| 119 |
-
file_name="AIEnergyScore.png",
|
| 120 |
-
mime="image/png"
|
| 121 |
-
)
|
| 122 |
-
|
| 123 |
def create_label(background_image, model_data):
|
| 124 |
"""
|
| 125 |
Create the label image by adding text from model_data to the background image.
|
|
|
|
| 30 |
|
| 31 |
# Dropdown for selecting a model
|
| 32 |
st.sidebar.write("### Instructions:")
|
| 33 |
+
st.sidebar.write("1. Select a model:")
|
| 34 |
model_options = data_df["model"].unique().tolist() # Get model options
|
| 35 |
selected_model = st.sidebar.selectbox(
|
| 36 |
+
"Scored Models", model_options, help="Start typing to search for a model"
|
| 37 |
) # Searchable dropdown
|
| 38 |
|
| 39 |
# Add step 2 instructions and move the Download button
|
| 40 |
+
st.sidebar.write("2. Download the label:")
|
| 41 |
|
| 42 |
+
# Filter the data for the selected model
|
| 43 |
model_data = data_df[data_df["model"] == selected_model].iloc[0]
|
| 44 |
|
| 45 |
+
# Dynamically select the background image based on the score
|
| 46 |
try:
|
| 47 |
score = int(model_data["score"]) # Convert to int
|
| 48 |
background_path = f"{score}.png" # E.g., "1.png", "2.png"
|
|
|
|
| 72 |
img_buffer.seek(0)
|
| 73 |
|
| 74 |
st.sidebar.download_button(
|
| 75 |
+
label="Download Label",
|
| 76 |
data=img_buffer,
|
| 77 |
file_name="AIEnergyScore.png",
|
| 78 |
mime="image/png"
|
|
|
|
| 82 |
st.sidebar.write("3. Share your label in technical reports, announcements, etc.")
|
| 83 |
st.sidebar.markdown("[AI Energy Score Leaderboard](https://huggingface.co/spaces/AIEnergyScore/Leaderboard)")
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
def create_label(background_image, model_data):
|
| 86 |
"""
|
| 87 |
Create the label image by adding text from model_data to the background image.
|