Spaces:
Running
Running
Fredrik Sitje
commited on
Commit
·
f8491a5
1
Parent(s):
077c9e3
Implement jurisdiction validation in Streamlit app. Added error handling to ensure a valid jurisdiction is selected before loading data, enhancing user experience and preventing potential issues during app usage.
Browse files- src/streamlit_app.py +21 -0
src/streamlit_app.py
CHANGED
|
@@ -49,6 +49,12 @@ hf_api = get_hf_api()
|
|
| 49 |
@st.cache_data
|
| 50 |
def load_grading_template(jurisdiction):
|
| 51 |
"""Load grading template from Hugging Face Dataset for the specified jurisdiction"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
try:
|
| 53 |
file_path = hf_hub_download(
|
| 54 |
repo_id=HF_DATASET_REPO,
|
|
@@ -700,6 +706,21 @@ elif st.session_state.logged_in:
|
|
| 700 |
jurisdiction = st.session_state.jurisdiction
|
| 701 |
current_index = st.session_state.current_index
|
| 702 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 703 |
# Load grading template for the selected jurisdiction
|
| 704 |
df = load_grading_template(jurisdiction)
|
| 705 |
|
|
|
|
| 49 |
@st.cache_data
|
| 50 |
def load_grading_template(jurisdiction):
|
| 51 |
"""Load grading template from Hugging Face Dataset for the specified jurisdiction"""
|
| 52 |
+
# Validate jurisdiction is set
|
| 53 |
+
if not jurisdiction or jurisdiction not in AVAILABLE_JURISDICTIONS:
|
| 54 |
+
st.error(f"❌ **Error**: Jurisdiction is not set or invalid. Please select a valid jurisdiction.")
|
| 55 |
+
st.error(f"Available jurisdictions: {', '.join(AVAILABLE_JURISDICTIONS)}")
|
| 56 |
+
st.stop()
|
| 57 |
+
|
| 58 |
try:
|
| 59 |
file_path = hf_hub_download(
|
| 60 |
repo_id=HF_DATASET_REPO,
|
|
|
|
| 706 |
jurisdiction = st.session_state.jurisdiction
|
| 707 |
current_index = st.session_state.current_index
|
| 708 |
|
| 709 |
+
# Safety check: ensure jurisdiction is set (handles case where user was logged in before jurisdiction feature was added)
|
| 710 |
+
if not jurisdiction or jurisdiction not in AVAILABLE_JURISDICTIONS:
|
| 711 |
+
st.error("❌ **Error**: Jurisdiction is not set. Please log out and log in again with a jurisdiction selected.")
|
| 712 |
+
if st.button("Logout"):
|
| 713 |
+
st.session_state.logged_in = False
|
| 714 |
+
st.session_state.username = None
|
| 715 |
+
st.session_state.jurisdiction = None
|
| 716 |
+
st.session_state.current_index = 0
|
| 717 |
+
st.session_state.show_guide = True
|
| 718 |
+
st.session_state.submitted_pairs = set()
|
| 719 |
+
st.session_state.original_selections = {}
|
| 720 |
+
st.session_state.has_unsaved_changes = {}
|
| 721 |
+
st.rerun()
|
| 722 |
+
st.stop()
|
| 723 |
+
|
| 724 |
# Load grading template for the selected jurisdiction
|
| 725 |
df = load_grading_template(jurisdiction)
|
| 726 |
|