forked from zihanxing/Multi-Modal-Local-File-Search-Engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_state.py
29 lines (23 loc) · 846 Bytes
/
session_state.py
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
# Import necessary library
import streamlit as st
class SessionState(object):
"""Store session state across app reruns."""
def __init__(self, **kwargs):
"""
Initialize the SessionState object with provided key-value pairs.
Args:
**kwargs: Arbitrary keyword arguments to initialize session state variables.
"""
for key, val in kwargs.items():
setattr(self, key, val)
def get_state(**kwargs):
"""
Get session state, creating it if necessary.
Args:
**kwargs: Arbitrary keyword arguments for initializing SessionState.
Returns:
SessionState: The session state object.
"""
if 'session_state' not in st.session_state:
st.session_state['session_state'] = SessionState(**kwargs)
return st.session_state['session_state']