Ludvig
commited on
Commit
·
af2035f
1
Parent(s):
dac77db
Adds reset button. Allow changing template or upload new settings without restarting
Browse files
app.py
CHANGED
|
@@ -61,7 +61,7 @@ def input_choice_callback():
|
|
| 61 |
st.session_state["step"] = 0
|
| 62 |
st.session_state["input_type"] = None
|
| 63 |
|
| 64 |
-
to_delete = ["classes", "count_data"]
|
| 65 |
for key in to_delete:
|
| 66 |
if key in st.session_state:
|
| 67 |
st.session_state.pop(key)
|
|
@@ -333,8 +333,8 @@ if st.session_state["step"] >= 2:
|
|
| 333 |
[str(c) for c in df[target_col].unique()]
|
| 334 |
)
|
| 335 |
|
| 336 |
-
st.subheader("The
|
| 337 |
-
col1, col2, col3 = st.columns([
|
| 338 |
with col2:
|
| 339 |
st.dataframe(df.head(5), hide_index=True)
|
| 340 |
st.write(f"{df.shape} (Showing first 5 rows)")
|
|
|
|
| 61 |
st.session_state["step"] = 0
|
| 62 |
st.session_state["input_type"] = None
|
| 63 |
|
| 64 |
+
to_delete = ["classes", "count_data", "uploaded_design_settings"]
|
| 65 |
for key in to_delete:
|
| 66 |
if key in st.session_state:
|
| 67 |
st.session_state.pop(key)
|
|
|
|
| 333 |
[str(c) for c in df[target_col].unique()]
|
| 334 |
)
|
| 335 |
|
| 336 |
+
st.subheader("The data")
|
| 337 |
+
col1, col2, col3 = st.columns([3, 2, 3])
|
| 338 |
with col2:
|
| 339 |
st.dataframe(df.head(5), hide_index=True)
|
| 340 |
st.write(f"{df.shape} (Showing first 5 rows)")
|
design.py
CHANGED
|
@@ -48,6 +48,8 @@ templates = {
|
|
| 48 |
}
|
| 49 |
}
|
| 50 |
|
|
|
|
|
|
|
| 51 |
|
| 52 |
def design_section(
|
| 53 |
num_classes,
|
|
@@ -55,6 +57,11 @@ def design_section(
|
|
| 55 |
):
|
| 56 |
output = {}
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
with st.form(key="settings_upload_form"):
|
| 59 |
design_text()
|
| 60 |
|
|
@@ -72,7 +79,7 @@ def design_section(
|
|
| 72 |
channels="RGB",
|
| 73 |
output_format="auto",
|
| 74 |
)
|
| 75 |
-
st.radio(
|
| 76 |
"Select template",
|
| 77 |
index=0,
|
| 78 |
options=["--"] + list(temp_collection.keys()),
|
|
@@ -86,17 +93,53 @@ def design_section(
|
|
| 86 |
"Upload design settings", type=["json"]
|
| 87 |
)
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
if uploaded_settings_path is not None:
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
else:
|
| 94 |
st.warning(
|
| 95 |
"No settings were uploaded and no templates were selected. Both are *optional*."
|
| 96 |
)
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
def get_uploaded_setting(key, default, type_=None, options=None):
|
| 99 |
-
if
|
|
|
|
|
|
|
|
|
|
| 100 |
out = st.session_state["uploaded_design_settings"][key]
|
| 101 |
if type_ is not None:
|
| 102 |
if not isinstance(out, type_):
|
|
|
|
| 48 |
}
|
| 49 |
}
|
| 50 |
|
| 51 |
+
template_selections = {}
|
| 52 |
+
|
| 53 |
|
| 54 |
def design_section(
|
| 55 |
num_classes,
|
|
|
|
| 57 |
):
|
| 58 |
output = {}
|
| 59 |
|
| 60 |
+
def reset_output_callback():
|
| 61 |
+
output.clear()
|
| 62 |
+
if "uploaded_design_settings" in st.session_state:
|
| 63 |
+
del st.session_state["uploaded_design_settings"]
|
| 64 |
+
|
| 65 |
with st.form(key="settings_upload_form"):
|
| 66 |
design_text()
|
| 67 |
|
|
|
|
| 79 |
channels="RGB",
|
| 80 |
output_format="auto",
|
| 81 |
)
|
| 82 |
+
template_selections[temp_collection_name] = st.radio(
|
| 83 |
"Select template",
|
| 84 |
index=0,
|
| 85 |
options=["--"] + list(temp_collection.keys()),
|
|
|
|
| 93 |
"Upload design settings", type=["json"]
|
| 94 |
)
|
| 95 |
|
| 96 |
+
if st.form_submit_button(
|
| 97 |
+
label="Apply settings", on_click=reset_output_callback
|
| 98 |
+
):
|
| 99 |
+
selections = [
|
| 100 |
+
(temp_coll_name, selection)
|
| 101 |
+
for temp_coll_name, selection in template_selections.items()
|
| 102 |
+
if selection != "--"
|
| 103 |
+
]
|
| 104 |
+
if len(selections) > 1:
|
| 105 |
+
st.warning("More than one template was selected. The first is applied.")
|
| 106 |
+
template_selected = "--"
|
| 107 |
+
if selections:
|
| 108 |
+
selection_temp_coll_name, selection = selections[0]
|
| 109 |
+
template_selected = selection
|
| 110 |
+
|
| 111 |
if uploaded_settings_path is not None:
|
| 112 |
+
if template_selected != "--":
|
| 113 |
+
st.warning(
|
| 114 |
+
"When both selecting a template and uploading settings, "
|
| 115 |
+
"the uploaded settings are used."
|
| 116 |
+
)
|
| 117 |
+
st.session_state["uploaded_design_settings"] = json.load(
|
| 118 |
+
uploaded_settings_path
|
| 119 |
+
)
|
| 120 |
+
elif template_selected != "--":
|
| 121 |
+
with open(
|
| 122 |
+
"templates/"
|
| 123 |
+
+ templates[selection_temp_coll_name][template_selected][
|
| 124 |
+
"settings"
|
| 125 |
+
],
|
| 126 |
+
"r",
|
| 127 |
+
) as jfile:
|
| 128 |
+
st.session_state["uploaded_design_settings"] = json.load(jfile)
|
| 129 |
else:
|
| 130 |
st.warning(
|
| 131 |
"No settings were uploaded and no templates were selected. Both are *optional*."
|
| 132 |
)
|
| 133 |
|
| 134 |
+
col1, col2, col1 = st.columns([5, 2.5, 5])
|
| 135 |
+
with col2:
|
| 136 |
+
st.button("Reset design", on_click=reset_output_callback)
|
| 137 |
+
|
| 138 |
def get_uploaded_setting(key, default, type_=None, options=None):
|
| 139 |
+
if (
|
| 140 |
+
"uploaded_design_settings" in st.session_state
|
| 141 |
+
and key in st.session_state["uploaded_design_settings"]
|
| 142 |
+
):
|
| 143 |
out = st.session_state["uploaded_design_settings"][key]
|
| 144 |
if type_ is not None:
|
| 145 |
if not isinstance(out, type_):
|