Spaces:
Sleeping
Sleeping
Sasha
commited on
Commit
·
e8c2dd4
1
Parent(s):
9c420d3
Adding initial streamlit app
Browse files
app.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2021 The HuggingFace Team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import streamlit as st
|
| 16 |
+
import json
|
| 17 |
+
import pandas as pd
|
| 18 |
+
import plotly.express as px
|
| 19 |
+
import numpy as np
|
| 20 |
+
|
| 21 |
+
with open('carbon-models-2.json', 'r') as fp:
|
| 22 |
+
carbondict= json.load(fp)
|
| 23 |
+
|
| 24 |
+
models= [k.split('/')[1] for k in carbondict.keys()]
|
| 25 |
+
carbon = [v[1] for v in carbondict.values()]
|
| 26 |
+
carbon = [4009.5 if x== '4' else x for x in carbon]
|
| 27 |
+
tasks = [v[0] for v in carbondict.values()]
|
| 28 |
+
tasks = ["other" if len(x) < 2 else x for x in tasks]
|
| 29 |
+
|
| 30 |
+
carbon_df = pd.DataFrame(
|
| 31 |
+
{'name': models,
|
| 32 |
+
'task': tasks,
|
| 33 |
+
'carbon': carbon
|
| 34 |
+
})
|
| 35 |
+
|
| 36 |
+
carbon_df.drop(carbon_df.loc[carbon_df['task']=='other'].index, inplace=True)
|
| 37 |
+
|
| 38 |
+
st.set_page_config(
|
| 39 |
+
page_title="Comparing the Carbon Footprint of Transformers",
|
| 40 |
+
page_icon="./hf-earth.png",
|
| 41 |
+
layout="wide",
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
st.title("Hugging Face Carbon Compare Tool")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
# Get the sidebar details
|
| 48 |
+
with st.sidebar.expander("Models", expanded=True):
|
| 49 |
+
st.image('./hf-earth.png')
|
| 50 |
+
# choose a dataset to analyze
|
| 51 |
+
model_name = st.selectbox(
|
| 52 |
+
f"Choose model to explore:",
|
| 53 |
+
models)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
fig = px.box(carbon_df, x=carbon_df['task'], y=carbon_df['carbon'], color='task', hover_name=carbon_df['name'])
|
| 57 |
+
#fig.update_traces(quartilemethod="exclusive") # or "inclusive", or "linear" by default
|
| 58 |
+
st.plotly_chart(fig, use_container_width=True)
|