Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,6 +29,10 @@ COLORS = {"pred": "#1f77b4", "actual": "#f2b702", "ref": "#5a5a5a"}
|
|
| 29 |
# Page / Theme
|
| 30 |
# =========================
|
| 31 |
st.set_page_config(page_title="ST_GeoMech_UCS", page_icon="logo.png", layout="wide")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
st.markdown("<style>header, footer{visibility:hidden !important;}</style>", unsafe_allow_html=True)
|
| 33 |
st.markdown(
|
| 34 |
"""
|
|
@@ -47,27 +51,49 @@ st.markdown(
|
|
| 47 |
""",
|
| 48 |
unsafe_allow_html=True
|
| 49 |
)
|
| 50 |
-
#
|
|
|
|
|
|
|
|
|
|
| 51 |
def add_password_gate() -> bool:
|
| 52 |
"""
|
| 53 |
Shows a branded access screen until the correct password is entered.
|
| 54 |
-
Returns True when access is granted
|
|
|
|
| 55 |
"""
|
| 56 |
-
#
|
|
|
|
| 57 |
try:
|
| 58 |
required = st.secrets.get("APP_PASSWORD", "")
|
| 59 |
except Exception:
|
| 60 |
required = os.environ.get("APP_PASSWORD", "")
|
| 61 |
|
| 62 |
-
# If
|
| 63 |
if not required:
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
# Already authenticated?
|
| 67 |
if st.session_state.get("auth_ok", False):
|
| 68 |
return True
|
| 69 |
|
| 70 |
-
#
|
| 71 |
st.markdown(
|
| 72 |
f"""
|
| 73 |
<div style="display:flex;align-items:center;gap:14px;margin:8px 0 6px 0;">
|
|
@@ -77,7 +103,7 @@ def add_password_gate() -> bool:
|
|
| 77 |
<div style="color:#667085;">Smart Thinking • Secure Access</div>
|
| 78 |
</div>
|
| 79 |
</div>
|
| 80 |
-
<div style="font-size:1.25rem;font-weight:700;margin:8px 0 4px 0;">Protected
|
| 81 |
<div style="color:#6b7280;margin-bottom:14px;">
|
| 82 |
Please enter your access key to continue.
|
| 83 |
</div>
|
|
@@ -85,7 +111,6 @@ def add_password_gate() -> bool:
|
|
| 85 |
unsafe_allow_html=True
|
| 86 |
)
|
| 87 |
|
| 88 |
-
# Input + action
|
| 89 |
pwd = st.text_input("Access key", type="password", placeholder="••••••••")
|
| 90 |
col1, _ = st.columns([1, 3])
|
| 91 |
with col1:
|
|
@@ -95,6 +120,8 @@ def add_password_gate() -> bool:
|
|
| 95 |
st.rerun()
|
| 96 |
else:
|
| 97 |
st.error("Incorrect key. Please try again.")
|
|
|
|
|
|
|
| 98 |
st.stop()
|
| 99 |
|
| 100 |
# =========================
|
|
|
|
| 29 |
# Page / Theme
|
| 30 |
# =========================
|
| 31 |
st.set_page_config(page_title="ST_GeoMech_UCS", page_icon="logo.png", layout="wide")
|
| 32 |
+
# … your CSS …
|
| 33 |
+
# 🔒 Password gate
|
| 34 |
+
add_password_gate()
|
| 35 |
+
# from here on, only authenticated users proceed
|
| 36 |
st.markdown("<style>header, footer{visibility:hidden !important;}</style>", unsafe_allow_html=True)
|
| 37 |
st.markdown(
|
| 38 |
"""
|
|
|
|
| 51 |
""",
|
| 52 |
unsafe_allow_html=True
|
| 53 |
)
|
| 54 |
+
# =========================
|
| 55 |
+
# Password
|
| 56 |
+
# =========================
|
| 57 |
+
# --- Password gate (branded, strict) ---
|
| 58 |
def add_password_gate() -> bool:
|
| 59 |
"""
|
| 60 |
Shows a branded access screen until the correct password is entered.
|
| 61 |
+
Returns True when access is granted.
|
| 62 |
+
Blocks (shows admin instructions) if APP_PASSWORD is not configured.
|
| 63 |
"""
|
| 64 |
+
# 1) Read password from Secrets or Env
|
| 65 |
+
required = ""
|
| 66 |
try:
|
| 67 |
required = st.secrets.get("APP_PASSWORD", "")
|
| 68 |
except Exception:
|
| 69 |
required = os.environ.get("APP_PASSWORD", "")
|
| 70 |
|
| 71 |
+
# 2) If not configured, BLOCK with admin message (no accidental bypass)
|
| 72 |
if not required:
|
| 73 |
+
st.markdown(
|
| 74 |
+
f"""
|
| 75 |
+
<div style="display:flex;align-items:center;gap:14px;margin:8px 0 6px 0;">
|
| 76 |
+
<img src="{inline_logo()}" style="width:56px;height:56px;object-fit:contain"/>
|
| 77 |
+
<div>
|
| 78 |
+
<div style="font-size:1.9rem;font-weight:800;">ST_GeoMech_UCS</div>
|
| 79 |
+
<div style="color:#667085;">Smart Thinking • Secure Access</div>
|
| 80 |
+
</div>
|
| 81 |
+
</div>
|
| 82 |
+
<div style="font-size:1.25rem;font-weight:700;margin:8px 0 4px 0;">Protected Area</div>
|
| 83 |
+
<div style="color:#6b7280;margin-bottom:14px;">
|
| 84 |
+
Admin action required: set <code>APP_PASSWORD</code> in <b>Settings → Secrets</b> (or as an
|
| 85 |
+
environment variable) and restart the Space.
|
| 86 |
+
</div>
|
| 87 |
+
""",
|
| 88 |
+
unsafe_allow_html=True,
|
| 89 |
+
)
|
| 90 |
+
st.stop()
|
| 91 |
|
| 92 |
+
# 3) Already authenticated?
|
| 93 |
if st.session_state.get("auth_ok", False):
|
| 94 |
return True
|
| 95 |
|
| 96 |
+
# 4) Branded prompt
|
| 97 |
st.markdown(
|
| 98 |
f"""
|
| 99 |
<div style="display:flex;align-items:center;gap:14px;margin:8px 0 6px 0;">
|
|
|
|
| 103 |
<div style="color:#667085;">Smart Thinking • Secure Access</div>
|
| 104 |
</div>
|
| 105 |
</div>
|
| 106 |
+
<div style="font-size:1.25rem;font-weight:700;margin:8px 0 4px 0;">Protected</div>
|
| 107 |
<div style="color:#6b7280;margin-bottom:14px;">
|
| 108 |
Please enter your access key to continue.
|
| 109 |
</div>
|
|
|
|
| 111 |
unsafe_allow_html=True
|
| 112 |
)
|
| 113 |
|
|
|
|
| 114 |
pwd = st.text_input("Access key", type="password", placeholder="••••••••")
|
| 115 |
col1, _ = st.columns([1, 3])
|
| 116 |
with col1:
|
|
|
|
| 120 |
st.rerun()
|
| 121 |
else:
|
| 122 |
st.error("Incorrect key. Please try again.")
|
| 123 |
+
|
| 124 |
+
# Don’t proceed until correct
|
| 125 |
st.stop()
|
| 126 |
|
| 127 |
# =========================
|