Spaces:
Runtime error
Runtime error
sashavor
commited on
Commit
·
32ac110
1
Parent(s):
3e93c13
adding pushing to hub
Browse files
app.py
CHANGED
|
@@ -1,10 +1,23 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
-
import os
|
|
|
|
| 5 |
|
| 6 |
HF_TOKEN = os.getenv('HUGGING_FACE_HUB_TOKEN')
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
st.set_page_config(
|
| 10 |
page_title="AI Carbon Calculator",
|
|
@@ -50,7 +63,7 @@ st.markdown('We will consider 3 aspects of your model: the dynamic emissions, id
|
|
| 50 |
|
| 51 |
st.markdown('### Dynamic Emissions')
|
| 52 |
with st.expander("Calculate the emissions produced by energy consumption of model training"):
|
| 53 |
-
with st.form(key='dynamic_emissions'):
|
| 54 |
col1, col2, col3, col4 = st.columns(4)
|
| 55 |
with col1:
|
| 56 |
hardware = st.selectbox('GPU used', TDP['name'].tolist())
|
|
@@ -78,9 +91,10 @@ with st.expander("Calculate the emissions produced by energy consumption of mode
|
|
| 78 |
st.metric(label="Dynamic emissions", value=str(dynamic_emissions)+' kilograms of CO2eq')
|
| 79 |
st.markdown('This is roughly equivalent to '+ str(round(dynamic_emissions/kg_per_mile,1)) + ' miles driven in an average US car'
|
| 80 |
' produced in 2021. [(Source: energy.gov)](https://www.energy.gov/eere/vehicles/articles/fotw-1223-january-31-2022-average-carbon-dioxide-emissions-2021-model-year)')
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
| 84 |
|
| 85 |
|
| 86 |
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
+
import os, csv
|
| 4 |
+
from huggingface_hub import hf_hub_download, HfApi
|
| 5 |
|
| 6 |
HF_TOKEN = os.getenv('HUGGING_FACE_HUB_TOKEN')
|
| 7 |
+
api = HfApi()
|
| 8 |
+
|
| 9 |
+
def write_to_csv(hardware, training_time, provider, carbon_intensity, dynamic_emissions):
|
| 10 |
+
with open('dynamic_emissions.csv','a', newline='') as f:
|
| 11 |
+
writer = csv.writer(f)
|
| 12 |
+
writer.writerow([hardware, training_time, provider, carbon_intensity, dynamic_emissions])
|
| 13 |
+
api.upload_file(
|
| 14 |
+
path_or_fileobj="dynamic_emissions.csv",
|
| 15 |
+
path_in_repo="dynamic_emissions.csv",
|
| 16 |
+
repo_id="sasha/co2_submissions",
|
| 17 |
+
repo_type="dataset",
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
hf_hub_download(repo_id="sasha/co2_submissions", filename="dynamic_emissions.csv", repo_type="dataset")
|
| 21 |
|
| 22 |
st.set_page_config(
|
| 23 |
page_title="AI Carbon Calculator",
|
|
|
|
| 63 |
|
| 64 |
st.markdown('### Dynamic Emissions')
|
| 65 |
with st.expander("Calculate the emissions produced by energy consumption of model training"):
|
| 66 |
+
with st.form(key='dynamic_emissions', clear_on_submit=True):
|
| 67 |
col1, col2, col3, col4 = st.columns(4)
|
| 68 |
with col1:
|
| 69 |
hardware = st.selectbox('GPU used', TDP['name'].tolist())
|
|
|
|
| 91 |
st.metric(label="Dynamic emissions", value=str(dynamic_emissions)+' kilograms of CO2eq')
|
| 92 |
st.markdown('This is roughly equivalent to '+ str(round(dynamic_emissions/kg_per_mile,1)) + ' miles driven in an average US car'
|
| 93 |
' produced in 2021. [(Source: energy.gov)](https://www.energy.gov/eere/vehicles/articles/fotw-1223-january-31-2022-average-carbon-dioxide-emissions-2021-model-year)')
|
| 94 |
+
st.form_submit_button(label="Share my data", help="Submit the data from your model anonymously for research purposes!",\
|
| 95 |
+
on_click = write_to_csv(hardware, training_time, provider, carbon_intensity, dynamic_emissions))
|
| 96 |
+
|
| 97 |
+
|
| 98 |
|
| 99 |
|
| 100 |
|