Skip to content

Commit 199f424

Browse files
committed
added password
1 parent 0b97c78 commit 199f424

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

app.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
GBIF_DB_PATH = os.path.join(DATA_DIR, "gbif_selected_FI_NO_merged.tsv")
4949
LIST_PLANTS_GENERA_PATH = os.path.join(DATA_DIR, "selected_genera.txt")
5050

51+
# Hard-coded app password; change the value to update access
52+
APP_PASSWORD = "metformin"
53+
5154
st.set_page_config(page_title="AURORA Pilot", layout="wide")
5255

5356
# ---- Session state init (so tables persist after any rerun, e.g., download clicks) ----
@@ -64,10 +67,39 @@
6467
"similarity_table": None,
6568
"active_smiles_query": None,
6669
"similarity_error": None,
70+
"auth_ok": False,
71+
"auth_error": False,
6772
}.items():
6873
if k not in st.session_state:
6974
st.session_state[k] = v
7075

76+
77+
def require_password():
78+
"""Optional password gate that does not disturb the rest of the UI."""
79+
if not APP_PASSWORD:
80+
return
81+
if st.session_state.get("auth_ok"):
82+
return
83+
84+
if st.session_state.get("auth_error"):
85+
st.error("Incorrect password, please try again.")
86+
87+
with st.form("auth_form"):
88+
st.subheader("Enter password to continue")
89+
password = st.text_input("Password", type="password")
90+
submitted = st.form_submit_button("Unlock")
91+
92+
if submitted:
93+
if password == APP_PASSWORD:
94+
st.session_state["auth_ok"] = True
95+
st.session_state["auth_error"] = False
96+
st.rerun()
97+
else:
98+
st.session_state["auth_error"] = True
99+
100+
if not st.session_state.get("auth_ok"):
101+
st.stop()
102+
71103
QUERY_PARAM_KEY = "select_compound"
72104
query_params: dict[str, list[str] | str] = {}
73105
raw_query_params = getattr(st, "query_params", None)
@@ -101,6 +133,8 @@
101133
st.session_state["compound_input"] = st.session_state.pop("pending_compound")
102134
st.session_state["auto_run"] = True
103135

136+
require_password()
137+
104138
# Cap the overall content width and shrink the first (#) column
105139
st.markdown(
106140
"""
@@ -714,6 +748,7 @@ def display_similarity_section(similarity_df: pd.DataFrame, compound_name: str |
714748
# Text input allows free-form entry for names or SMILES strings
715749
compound = st.text_input(
716750
"Compound",
751+
value=st.session_state.get("compound_input", DEFAULT_COMPOUND),
717752
key="compound_input",
718753
help="Enter a compound name.",
719754
)
@@ -893,4 +928,4 @@ def display_similarity_section(similarity_df: pd.DataFrame, compound_name: str |
893928
)
894929

895930

896-
st.caption('<span style="font-size: x-small;">App version: 3.1; © 2025 Daniel Nicorici, Juha Klefström — University of Helsinki</span>', unsafe_allow_html=True)
931+
st.caption('<span style="font-size: x-small;">App version: 3.2; © 2025 Daniel Nicorici, Juha Klefström — University of Helsinki</span>', unsafe_allow_html=True)

0 commit comments

Comments
 (0)