File size: 2,203 Bytes
605b5ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# This streamlit demonstration is meant to simulate two types of memory within cognitive architecture:
# Each time we remember a moment, we construct it anew.
# We use the building blocks of Episodic Memory which is recall of feelings of being somewhere.
# We also use Semantic Memory which is concrete knowledge about our world and about our personal history.
# With Episodic Memory, its purpose is to provide us with coherence connecting events.  In Episodic Memory, accuracy is less important than consistency.
# In order to have a strong sense of self, it is important that our memories fit with our beliefs and feelings about ourselves.

# Initialization
if 'key' not in st.session_state:
    st.session_state['key'] = 'value'

# Session State also supports attribute based syntax
if 'key' not in st.session_state:
    st.session_state.key = 'value'
    
# Read
st.write(st.session_state.key)

# Outputs: value

st.session_state.key = 'value2'     # Attribute API
st.session_state['key'] = 'value2'  # Dictionary like API

st.write(st.session_state)

# With magic:
st.session_state


st.write(st.session_state['value'])

# Throws an exception!

# Delete a single key-value pair
del st.session_state[key]

# Delete all the items in Session state
for key in st.session_state.keys():
    del st.session_state[key]
    

st.text_input("Your name", key="name")

# This exists now:
st.session_state.name

def form_callback():
    st.write(st.session_state.my_slider)
    st.write(st.session_state.my_checkbox)

with st.form(key='my_form'):
    slider_input = st.slider('My slider', 0, 10, 5, key='my_slider')
    checkbox_input = st.checkbox('Yes or No', key='my_checkbox')
    submit_button = st.form_submit_button(label='Submit', on_click=form_callback)
    
slider = st.slider(
    label='My Slider', min_value=1,
    max_value=10, value=5, key='my_slider')

st.session_state.my_slider = 7

# Throws an exception!

st.session_state.my_slider = 7

slider = st.slider(
    label='Choose a Value', min_value=1,
    max_value=10, value=5, key='my_slider')
    
if 'my_button' not in st.session_state:
    st.session_state.my_button = True

st.button('My button', key='my_button')

# Throws an exception!