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