Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,6 +47,37 @@ st.markdown(
|
|
| 47 |
""",
|
| 48 |
unsafe_allow_html=True
|
| 49 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# =========================
|
| 52 |
# Helpers
|
|
|
|
| 47 |
""",
|
| 48 |
unsafe_allow_html=True
|
| 49 |
)
|
| 50 |
+
# ---------- Password Gate (add this near the top, before any model loading) ----------
|
| 51 |
+
import os, streamlit as st
|
| 52 |
+
|
| 53 |
+
def _require_password():
|
| 54 |
+
"""Stop the app until the correct password is entered.
|
| 55 |
+
Password is read from environment variable APP_PASSWORD.
|
| 56 |
+
If APP_PASSWORD is not set, the gate is disabled (app is open)."""
|
| 57 |
+
expected = os.environ.get("APP_PASSWORD", "").strip()
|
| 58 |
+
if not expected:
|
| 59 |
+
return # gate disabled (no password configured)
|
| 60 |
+
|
| 61 |
+
# already authenticated this session?
|
| 62 |
+
if st.session_state.get("_authed", False):
|
| 63 |
+
return
|
| 64 |
+
|
| 65 |
+
st.title("🔒 Protected")
|
| 66 |
+
st.write("This app requires a password to continue.")
|
| 67 |
+
|
| 68 |
+
with st.form("pw_form", clear_on_submit=False):
|
| 69 |
+
pw = st.text_input("Password", type="password")
|
| 70 |
+
ok = st.form_submit_button("Enter")
|
| 71 |
+
if ok:
|
| 72 |
+
if pw == expected:
|
| 73 |
+
st.session_state["_authed"] = True
|
| 74 |
+
st.rerun()
|
| 75 |
+
else:
|
| 76 |
+
st.error("Incorrect password. Please try again.")
|
| 77 |
+
st.stop() # block the rest of the script until authenticated
|
| 78 |
+
|
| 79 |
+
_require_password()
|
| 80 |
+
# -------------------------------------------------------------------------------
|
| 81 |
|
| 82 |
# =========================
|
| 83 |
# Helpers
|