File size: 5,463 Bytes
0687bfd
 
 
 
 
 
70db274
 
 
 
541593d
 
f5bc51d
70db274
 
 
 
 
 
 
 
 
 
 
 
 
 
82ed661
70db274
82ed661
 
70db274
82ed661
 
 
 
541593d
82ed661
 
 
 
 
541593d
3139444
83432dd
541593d
5b8e533
541593d
 
5b8e533
541593d
70db274
dbb7425
541593d
5b8e533
 
 
 
 
 
 
70db274
5b8e533
 
 
 
541593d
f5bc51d
83432dd
70db274
 
 
 
 
 
 
 
83432dd
541593d
83432dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541593d
83432dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd369fc
ea74654
 
bd369fc
 
 
 
 
 
 
 
2dab0f4
541593d
2dab0f4
bd369fc
4575207
 
 
bd369fc
4575207
f76ab84
4575207
 
 
 
 
0687bfd
541593d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import streamlit as st
import pandas as pd
from PIL import Image, ImageDraw, ImageFont
import io

def main():
    st.markdown(
        """
        <style>
            .stMultiSelect [data-baseweb="tag"] {
                background-color: #3fa45bff !important;
                color: white !important;
                font-weight: medium;
                border-radius: 5px;
                padding: 5px 10px;
            }
            .stMultiSelect [data-baseweb="tag"]:hover {
                background-color: #358d4d !important;
            }
            .stMultiSelect input {
                color: black !important;
            }
        </style>
        """,
        unsafe_allow_html=True,
    )

    with st.sidebar:
        col1, col2 = st.columns([1, 5])
        with col1:
            logo = Image.open("logo.png")
            resized_logo = logo.resize((50, 50))
            st.image(resized_logo)
        with col2:
            st.markdown(
                """
                <div style="display: flex; align-items: center; gap: 10px; margin: 0; padding: 0; font-family: 'Inter', sans-serif; font-size: 26px; font-weight: bold;">
                    AI Energy Score
                </div>
                """,
                unsafe_allow_html=True,
            )
    
    st.sidebar.markdown("<hr style='border: 1px solid gray; margin: 15px 0;'>", unsafe_allow_html=True)
    st.sidebar.write("### Generate Label:")
    
    task_order = [
        "Text Generation", "Image Generation", "Text Classification", "Image Classification", "Image Captioning", 
        "Summarization", "Speech-to-Text (ASR)", "Object Detection", "Question Answering", "Sentence Similarity"
    ]
    
    st.sidebar.write("#### 1. Select task(s) to view models")
    selected_tasks = st.sidebar.multiselect("", options=task_order, default=["Text Generation"])
    
    task_to_file = {
        "Text Generation": "text_gen_energyscore.csv",
        "Image Generation": "image_generation_energyscore.csv",
        "Text Classification": "text_classification_energyscore.csv",
        "Image Classification": "image_classification_energyscore.csv",
        "Image Captioning": "image_caption_energyscore.csv",
        "Summarization": "summarization_energyscore.csv",
        "Speech-to-Text (ASR)": "asr_energyscore.csv",
        "Object Detection": "object_detection_energyscore.csv",
        "Question Answering": "question_answering_energyscore.csv",
        "Sentence Similarity": "sentence_similarity_energyscore.csv"
    }
    
    st.sidebar.write("#### 2. Select a model to generate label")
    default_model_data = {
        'provider': "AI Provider",
        'model': "Model Name",
        'full_model': "AI Provider/Model Name",
        'date': "",
        'task': "",
        'hardware': "",
        'energy': "?",
        'score': 5
    }
    
    if not selected_tasks:
        model_data = default_model_data
    else:
        dfs = []
        for task in selected_tasks:
            file_name = task_to_file[task]
            try:
                df = pd.read_csv(file_name)
            except FileNotFoundError:
                st.sidebar.error(f"Could not find '{file_name}' for task {task}!")
                continue
            except Exception as e:
                st.sidebar.error(f"Error reading '{file_name}' for task {task}: {e}")
                continue

            df['full_model'] = df['model']
            df[['provider', 'model']] = df['model'].str.split(pat='/', n=1, expand=True)
            df['energy'] = (df['total_gpu_energy'] * 1000).round(2)  # Convert to Wh and round to 2 decimal places
            df['score'] = df['energy_score'].fillna(1).astype(int)
            df['date'] = "February 2025"
            df['hardware'] = "NVIDIA H100-80GB"
            df['task'] = task

            dfs.append(df)

        if not dfs:
            model_data = default_model_data
        else:
            data_df = pd.concat(dfs, ignore_index=True)
            if data_df.empty:
                model_data = default_model_data
            else:
                model_options = data_df["full_model"].unique().tolist()
                selected_model = st.sidebar.selectbox(
                    "Scored Models",
                    model_options,
                    help="Start typing to search for a model"
                )
                model_data = data_df[data_df["full_model"] == selected_model].iloc[0]

    st.sidebar.write("#### 3. Download the label")
    try:
        score = int(model_data["score"])
        background_path = f"{score}.png"
        background = Image.open(background_path).convert("RGBA")
    except FileNotFoundError:
        st.sidebar.error(f"Could not find background image '{score}.png'. Using default background.")
        background = Image.open("default_background.png").convert("RGBA")
    except ValueError:
        st.sidebar.error(f"Invalid score '{model_data['score']}'. Score must be an integer.")
        return

    final_size = (520, 728)
    generated_label = background.resize(final_size, Image.Resampling.LANCZOS)
    st.image(generated_label, caption="Generated Label Preview", width=520)

    img_buffer = io.BytesIO()
    generated_label.save(img_buffer, format="PNG")
    img_buffer.seek(0)

    st.sidebar.download_button(
        label="Download",
        data=img_buffer,
        file_name="AIEnergyScore.png",
        mime="image/png"
    )

if __name__ == "__main__":
    main()