Spaces:
Running
Running
theo
commited on
Commit
·
05edfc3
1
Parent(s):
827b7ef
simplify error msg on empty state
Browse files- tagging_app.py +11 -3
tagging_app.py
CHANGED
|
@@ -102,7 +102,7 @@ def validate_dict(w: st.delta_generator.DeltaGenerator, state_dict: Dict):
|
|
| 102 |
w.error(e)
|
| 103 |
|
| 104 |
|
| 105 |
-
def new_state():
|
| 106 |
return {
|
| 107 |
"task_categories": [],
|
| 108 |
"task_ids": [],
|
|
@@ -116,6 +116,10 @@ def new_state():
|
|
| 116 |
}
|
| 117 |
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
state = new_state()
|
| 120 |
datasets_md = load_ds_datas()
|
| 121 |
existing_tag_sets = {name: mds["metadata"] for name, mds in datasets_md.items()}
|
|
@@ -156,7 +160,7 @@ if leftbtn.button("pre-load"):
|
|
| 156 |
initial_state = existing_tag_sets[preloaded_id]
|
| 157 |
state = initial_state or new_state()
|
| 158 |
st.experimental_set_query_params(preload_dataset=preloaded_id)
|
| 159 |
-
if
|
| 160 |
if rightbtn.button("flush state"):
|
| 161 |
state = new_state()
|
| 162 |
initial_state = None
|
|
@@ -340,7 +344,11 @@ rightcol.markdown(
|
|
| 340 |
|
| 341 |
"""
|
| 342 |
)
|
| 343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
|
| 345 |
rightcol.markdown(
|
| 346 |
f"""
|
|
|
|
| 102 |
w.error(e)
|
| 103 |
|
| 104 |
|
| 105 |
+
def new_state() -> Dict[str, List]:
|
| 106 |
return {
|
| 107 |
"task_categories": [],
|
| 108 |
"task_ids": [],
|
|
|
|
| 116 |
}
|
| 117 |
|
| 118 |
|
| 119 |
+
def is_state_empty(state: Dict[str, List]) -> bool:
|
| 120 |
+
return sum(len(v) if v is not None else 0 for v in state.values()) > 0
|
| 121 |
+
|
| 122 |
+
|
| 123 |
state = new_state()
|
| 124 |
datasets_md = load_ds_datas()
|
| 125 |
existing_tag_sets = {name: mds["metadata"] for name, mds in datasets_md.items()}
|
|
|
|
| 160 |
initial_state = existing_tag_sets[preloaded_id]
|
| 161 |
state = initial_state or new_state()
|
| 162 |
st.experimental_set_query_params(preload_dataset=preloaded_id)
|
| 163 |
+
if is_state_empty(state):
|
| 164 |
if rightbtn.button("flush state"):
|
| 165 |
state = new_state()
|
| 166 |
initial_state = None
|
|
|
|
| 344 |
|
| 345 |
"""
|
| 346 |
)
|
| 347 |
+
if is_state_empty(state):
|
| 348 |
+
rightcol.markdown("❌ This is an invalid tagset: it's empty!")
|
| 349 |
+
else:
|
| 350 |
+
validate_dict(rightcol, state)
|
| 351 |
+
|
| 352 |
|
| 353 |
rightcol.markdown(
|
| 354 |
f"""
|