Skip to content

Commit

Permalink
adding export-import session
Browse files Browse the repository at this point in the history
  • Loading branch information
LemurPwned committed Dec 20, 2024
1 parent b0392b8 commit 638bd57
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions view/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
from autofit import autofit
from helpers import simulate_pimm, simulate_vsd
from utils import GENERIC_BOUNDS, GENERIC_UNITS
import json


def export_session_state():
export_dict = {}
opts = ["_btn", "_file", "_state", "low_", "up_", "check_", "upload"]
for k, v in st.session_state.items():
skip = any(forb_opts in k for forb_opts in opts)
if not skip:
export_dict[k] = v

return json.dumps(export_dict)


def import_session_state(file):
for k, v in json.load(file).items():
st.session_state[k] = v


with st.expander("# Read me"):
st.write(
Expand All @@ -17,13 +35,32 @@
)

with st.sidebar:
st.file_uploader(
"Upload your data here",
help="Upload your data here. Must be `\t` separated values and have H and f headers.",
type=["txt", "dat"],
accept_multiple_files=False,
key="upload",
)
with st.expander("Export/Import"):
st.download_button(
label="Export session state",
data=export_session_state(),
file_name="session_state.json",
mime="application/json",
type="primary",
)

st.file_uploader(
"Upload session state",
help="Upload your data here. Must be `\t` separated values and have H and f headers.",
type=["json"],
accept_multiple_files=False,
key="import_file",
)
if st.session_state.import_file:
import_session_state(st.session_state.import_file)

st.file_uploader(
"Upload your data here",
help="Upload your data here. Must be `\t` separated values and have H and f headers.",
type=["txt", "dat"],
accept_multiple_files=False,
key="upload",
)
N = st.number_input(
"Number of layers", min_value=1, max_value=10, value=1, key="N", format="%d"
)
Expand Down Expand Up @@ -149,7 +186,6 @@
help="Maximum frequency (cutoff) visible in plot",
)


pimm_tab, vsd_tab, opt_tab = st.tabs(["PIMM", "VSD", "Optimization"])
with opt_tab:
with st.expander("Optimization parameters"):
Expand Down

0 comments on commit 638bd57

Please sign in to comment.