Update black_forest_streamlit.py
This commit is contained in:
parent
278a79bf01
commit
fca5bd1393
1 changed files with 20 additions and 4 deletions
|
|
@ -17,11 +17,29 @@ from sqlalchemy.ext.declarative import declarative_base
|
|||
from sqlalchemy.orm import sessionmaker, relationship
|
||||
from sqlalchemy.sql import func
|
||||
from streamlit_cookies_manager import EncryptedCookieManager
|
||||
import secrets
|
||||
|
||||
# --- Database Setup ---
|
||||
# --- Database and Secret Setup ---
|
||||
DATA_DIR = "data"
|
||||
os.makedirs(DATA_DIR, exist_ok=True)
|
||||
DB_PATH = f"sqlite:///{os.path.join(DATA_DIR, 'image_metadata.db')}"
|
||||
SECRET_FILE = os.path.join(DATA_DIR, "cookie_secret.txt")
|
||||
|
||||
# Generate or load cookie secret
|
||||
def get_or_create_cookie_secret():
|
||||
if os.path.exists(SECRET_FILE):
|
||||
with open(SECRET_FILE, "r") as f:
|
||||
return f.read().strip()
|
||||
else:
|
||||
# Generate a secure random secret (32 bytes, hex-encoded = 64 characters)
|
||||
secret = secrets.token_hex(32)
|
||||
with open(SECRET_FILE, "w") as f:
|
||||
f.write(secret)
|
||||
return secret
|
||||
|
||||
COOKIE_SECRET = get_or_create_cookie_secret()
|
||||
|
||||
# SQLAlchemy setup
|
||||
engine = create_engine(DB_PATH, echo=False)
|
||||
Base = declarative_base()
|
||||
|
||||
|
|
@ -61,9 +79,7 @@ Base.metadata.create_all(engine)
|
|||
Session = sessionmaker(bind=engine)
|
||||
|
||||
# --- Cookie Manager Setup ---
|
||||
cookies = EncryptedCookieManager(
|
||||
password="your-secret-password-here", # Replace with a secure password
|
||||
)
|
||||
cookies = EncryptedCookieManager(password=COOKIE_SECRET)
|
||||
if not cookies.ready():
|
||||
st.stop() # Wait for cookies to be ready
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue