Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,35 @@ import requests
|
|
3 |
import streamlit as st
|
4 |
import os
|
5 |
import openai
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
openai.api_type = "azure"
|
|
|
3 |
import streamlit as st
|
4 |
import os
|
5 |
import openai
|
6 |
+
import hmac
|
7 |
+
|
8 |
+
|
9 |
+
def check_password():
|
10 |
+
"""Returns `True` if the user had the correct password."""
|
11 |
+
|
12 |
+
def password_entered():
|
13 |
+
"""Checks whether a password entered by the user is correct."""
|
14 |
+
if hmac.compare_digest(st.session_state["password"], os.environ.get("PASSWORT")):
|
15 |
+
st.session_state["password_correct"] = True
|
16 |
+
del st.session_state["password"] # Don't store the password.
|
17 |
+
else:
|
18 |
+
st.session_state["password_correct"] = False
|
19 |
+
|
20 |
+
# Return True if the password is validated.
|
21 |
+
if st.session_state.get("password_correct", False):
|
22 |
+
return True
|
23 |
+
|
24 |
+
# Show input for password.
|
25 |
+
st.text_input(
|
26 |
+
"Password", type="password", on_change=password_entered, key="password"
|
27 |
+
)
|
28 |
+
if "password_correct" in st.session_state:
|
29 |
+
st.error("😕 Password incorrect")
|
30 |
+
return False
|
31 |
+
|
32 |
+
|
33 |
+
if not check_password():
|
34 |
+
st.stop() # Do not continue if check_password is not True.
|
35 |
|
36 |
|
37 |
openai.api_type = "azure"
|