-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from robertmcleod2/add-auth
Add auth
- Loading branch information
Showing
6 changed files
with
62 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
OPENAI_API_KEY=<OPENAI_API_KEY> | ||
STREAMLIT_PASSWORD=1234 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
import time | ||
|
||
import streamlit as st | ||
import logging | ||
|
||
|
||
def check_password(): | ||
"""Returns `True` if the user had the correct password.""" | ||
|
||
def password_entered(): | ||
"""Checks whether a password entered by the user is correct.""" | ||
password = os.getenv("STREAMLIT_PASSWORD") | ||
if not password: | ||
st.error("😕 Password not set") | ||
return False | ||
if st.session_state["password"] == password: | ||
st.session_state["password_correct"] = True | ||
st.session_state["show_success"] = True | ||
del st.session_state["password"] # Don't store the password. | ||
else: | ||
st.session_state["password_correct"] = False | ||
|
||
# Return True if the password is validated. | ||
if st.session_state.get("password_correct", False): | ||
if st.session_state.get("show_success", False): | ||
placeholder = st.empty() | ||
placeholder.success("🎉 Password correct") | ||
time.sleep(1.5) | ||
placeholder.empty() | ||
st.session_state["show_success"] = False | ||
return True | ||
|
||
# Show input for password. | ||
st.text_input("Password", type="password", on_change=password_entered, key="password") | ||
if "password_correct" in st.session_state: | ||
st.error("😕 Password incorrect") | ||
return False |