Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
# app.py
|
2 |
-
|
3 |
import streamlit as st
|
4 |
import hmac
|
5 |
import os
|
@@ -18,42 +16,6 @@ def main(answer_mode: str):
|
|
18 |
st.error("You must provide a valid OpenAI API Key to proceed.")
|
19 |
st.stop()
|
20 |
|
21 |
-
def check_password():
|
22 |
-
"""Returns `True` if the user had a correct password."""
|
23 |
-
def login_form():
|
24 |
-
"""Form with widgets to collect user information"""
|
25 |
-
with st.form("Credentials"):
|
26 |
-
st.text_input("Username", key="username")
|
27 |
-
st.text_input("Password", type="password", key="password")
|
28 |
-
st.form_submit_button("Log in", on_click=password_entered)
|
29 |
-
|
30 |
-
def password_entered():
|
31 |
-
"""Checks whether a password entered by the user is correct."""
|
32 |
-
if st.session_state["username"] in st.secrets[
|
33 |
-
"passwords"
|
34 |
-
] and hmac.compare_digest(
|
35 |
-
st.session_state["password"],
|
36 |
-
st.secrets.passwords[st.session_state["username"]],
|
37 |
-
):
|
38 |
-
st.session_state["password_correct"] = True
|
39 |
-
del st.session_state["password"]
|
40 |
-
del st.session_state["username"]
|
41 |
-
else:
|
42 |
-
st.session_state["password_correct"] = False
|
43 |
-
|
44 |
-
# Return True if the username + password is validated.
|
45 |
-
if st.session_state.get("password_correct", False):
|
46 |
-
return True
|
47 |
-
|
48 |
-
# Show inputs for username + password.
|
49 |
-
login_form()
|
50 |
-
if "password_correct" in st.session_state:
|
51 |
-
st.error("😕 User not known or password incorrect")
|
52 |
-
return False
|
53 |
-
|
54 |
-
if not check_password():
|
55 |
-
st.stop()
|
56 |
-
|
57 |
def initialize_session_state():
|
58 |
if "messages" not in st.session_state:
|
59 |
st.session_state.messages = [
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import hmac
|
3 |
import os
|
|
|
16 |
st.error("You must provide a valid OpenAI API Key to proceed.")
|
17 |
st.stop()
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
def initialize_session_state():
|
20 |
if "messages" not in st.session_state:
|
21 |
st.session_state.messages = [
|