Spaces:
Running
Running
Add password
Browse files
app.py
CHANGED
@@ -91,6 +91,33 @@ if "article_links" not in st.session_state:
|
|
91 |
if "final_articles" not in st.session_state:
|
92 |
st.session_state["final_articles"] = []
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
col1, col2 = st.columns([2, 1])
|
95 |
|
96 |
col1.title("AI journalist")
|
|
|
91 |
if "final_articles" not in st.session_state:
|
92 |
st.session_state["final_articles"] = []
|
93 |
|
94 |
+
def check_password():
|
95 |
+
"""Returns `True` if the user had the correct password."""
|
96 |
+
|
97 |
+
def password_entered():
|
98 |
+
"""Checks whether a password entered by the user is correct."""
|
99 |
+
if hmac.compare_digest(st.session_state["password"], os.environ.get("PASSWORD")):
|
100 |
+
st.session_state["password_correct"] = True
|
101 |
+
del st.session_state["password"] # Don't store the password.
|
102 |
+
else:
|
103 |
+
st.session_state["password_correct"] = False
|
104 |
+
|
105 |
+
# Return True if the password is validated.
|
106 |
+
if st.session_state.get("password_correct", False):
|
107 |
+
return True
|
108 |
+
|
109 |
+
# Show input for password.
|
110 |
+
st.text_input(
|
111 |
+
"Password", type="password", on_change=password_entered, key="password"
|
112 |
+
)
|
113 |
+
if "password_correct" in st.session_state:
|
114 |
+
st.error("😕 Password incorrect")
|
115 |
+
return False
|
116 |
+
|
117 |
+
|
118 |
+
if not check_password():
|
119 |
+
st.stop() # Do not continue if check_password is not True.
|
120 |
+
|
121 |
col1, col2 = st.columns([2, 1])
|
122 |
|
123 |
col1.title("AI journalist")
|