Wauplin HF staff commited on
Commit
54a7876
1 Parent(s): 1f6c998

Fix session state

Browse files

Session state must be set only once:

```py
if "is_shared" not in st.session_state:
st.session_state["is_shared"] = False
```

otherwise the `st.session_state["is_shared"] = False` is run on each page reload. This is how streamlit works (each time to interact with the UI, the all page is rerun). I tested it locally and it should work now :)

Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -68,7 +68,9 @@ model_info = "N/A"
68
  ### Conversion factors
69
  kg_per_mile = 0.348
70
  embodied_conversion_factor = 0.0289
71
- st.session_state["is_shared"] = False
 
 
72
 
73
  electricity = pd.read_csv(electricity_url)
74
  servers = pd.read_csv(server_url)
@@ -190,7 +192,7 @@ div.stButton > button:first-child {
190
 
191
  buttoncol1, buttoncol2, buttoncol3 = st.columns(3)
192
  with buttoncol2:
193
- if st.session_state["is_shared"] == False:
194
  submitted = st.button(label="Share my CO2 data!", on_click = lambda *args: write_to_csv(hardware, gpu_tdp, num_gpus, training_time, provider, carbon_intensity, dynamic_emissions, experimentation_time, experimental_emissions, pue, pue_emissions, embodied_type, embodied_emissions, model_info))
195
  else:
196
  st.info('Thank you! Your data has been shared in https://huggingface.co/datasets/sasha/co2_submissions.')
 
68
  ### Conversion factors
69
  kg_per_mile = 0.348
70
  embodied_conversion_factor = 0.0289
71
+
72
+ if "is_shared" not in st.session_state:
73
+ st.session_state["is_shared"] = False
74
 
75
  electricity = pd.read_csv(electricity_url)
76
  servers = pd.read_csv(server_url)
 
192
 
193
  buttoncol1, buttoncol2, buttoncol3 = st.columns(3)
194
  with buttoncol2:
195
+ if not st.session_state["is_shared"]:
196
  submitted = st.button(label="Share my CO2 data!", on_click = lambda *args: write_to_csv(hardware, gpu_tdp, num_gpus, training_time, provider, carbon_intensity, dynamic_emissions, experimentation_time, experimental_emissions, pue, pue_emissions, embodied_type, embodied_emissions, model_info))
197
  else:
198
  st.info('Thank you! Your data has been shared in https://huggingface.co/datasets/sasha/co2_submissions.')