Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,40 @@ import os
|
|
3 |
import re
|
4 |
from openai import AzureOpenAI
|
5 |
from streamlit_pills import pills
|
|
|
|
|
|
|
6 |
|
7 |
st.set_page_config(layout="wide")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# Initialize the Azure OpenAI client
|
10 |
client = AzureOpenAI(
|
11 |
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
|
|
|
3 |
import re
|
4 |
from openai import AzureOpenAI
|
5 |
from streamlit_pills import pills
|
6 |
+
import hmac
|
7 |
+
|
8 |
+
|
9 |
|
10 |
st.set_page_config(layout="wide")
|
11 |
|
12 |
+
|
13 |
+
def check_password():
|
14 |
+
"""Returns `True` if the user had the correct password."""
|
15 |
+
|
16 |
+
def password_entered():
|
17 |
+
"""Checks whether a password entered by the user is correct."""
|
18 |
+
if hmac.compare_digest(st.session_state["password"], st.secrets["password"]):
|
19 |
+
st.session_state["password_correct"] = True
|
20 |
+
del st.session_state["password"] # Don't store the password.
|
21 |
+
else:
|
22 |
+
st.session_state["password_correct"] = False
|
23 |
+
|
24 |
+
# Return True if the password is validated.
|
25 |
+
if st.session_state.get("password_correct", False):
|
26 |
+
return True
|
27 |
+
|
28 |
+
# Show input for password.
|
29 |
+
st.text_input(
|
30 |
+
"Password", type="password", on_change=password_entered, key="password"
|
31 |
+
)
|
32 |
+
if "password_correct" in st.session_state:
|
33 |
+
st.error("😕 Password incorrect")
|
34 |
+
return False
|
35 |
+
|
36 |
+
|
37 |
+
if not check_password():
|
38 |
+
st.stop() # Do not continue if check_password is not True.
|
39 |
+
|
40 |
# Initialize the Azure OpenAI client
|
41 |
client = AzureOpenAI(
|
42 |
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
|