Add password authentication and full demo application
Browse files
.streamlit/secrets.toml.example
CHANGED
|
@@ -1,5 +1,14 @@
|
|
| 1 |
-
#
|
| 2 |
-
# DO NOT commit secrets.toml!
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPARKNET Secrets Configuration
|
| 2 |
+
# Copy this to secrets.toml (DO NOT commit secrets.toml!)
|
| 3 |
|
| 4 |
+
# Authentication - set your password
|
| 5 |
+
[auth]
|
| 6 |
+
password = "your-secure-password-here"
|
| 7 |
+
|
| 8 |
+
# Or for multiple users:
|
| 9 |
+
# [auth]
|
| 10 |
+
# passwords = { admin = "admin123", viewer = "viewer456" }
|
| 11 |
+
|
| 12 |
+
# API Keys (free tiers)
|
| 13 |
+
GROQ_API_KEY = "your-groq-key"
|
| 14 |
+
HF_TOKEN = "your-huggingface-token"
|
demo/app.py
CHANGED
|
@@ -21,7 +21,7 @@ from datetime import datetime
|
|
| 21 |
PROJECT_ROOT = Path(__file__).parent.parent
|
| 22 |
sys.path.insert(0, str(PROJECT_ROOT))
|
| 23 |
|
| 24 |
-
# Page configuration
|
| 25 |
st.set_page_config(
|
| 26 |
page_title="SPARKNET Document Intelligence",
|
| 27 |
page_icon="π₯",
|
|
@@ -29,6 +29,15 @@ st.set_page_config(
|
|
| 29 |
initial_sidebar_state="expanded",
|
| 30 |
)
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# Custom CSS
|
| 33 |
st.markdown("""
|
| 34 |
<style>
|
|
|
|
| 21 |
PROJECT_ROOT = Path(__file__).parent.parent
|
| 22 |
sys.path.insert(0, str(PROJECT_ROOT))
|
| 23 |
|
| 24 |
+
# Page configuration - MUST be first Streamlit command
|
| 25 |
st.set_page_config(
|
| 26 |
page_title="SPARKNET Document Intelligence",
|
| 27 |
page_icon="π₯",
|
|
|
|
| 29 |
initial_sidebar_state="expanded",
|
| 30 |
)
|
| 31 |
|
| 32 |
+
# Authentication - require login before showing app
|
| 33 |
+
from auth import check_password, show_logout_button
|
| 34 |
+
|
| 35 |
+
if not check_password():
|
| 36 |
+
st.stop()
|
| 37 |
+
|
| 38 |
+
# Show logout button in sidebar
|
| 39 |
+
show_logout_button()
|
| 40 |
+
|
| 41 |
# Custom CSS
|
| 42 |
st.markdown("""
|
| 43 |
<style>
|
demo/auth.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Simple Password Authentication for SPARKNET
|
| 3 |
+
|
| 4 |
+
Provides password-based access control for the Streamlit app.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import streamlit as st
|
| 8 |
+
import hashlib
|
| 9 |
+
import hmac
|
| 10 |
+
from typing import Optional
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def hash_password(password: str) -> str:
|
| 14 |
+
"""Hash a password for secure storage."""
|
| 15 |
+
return hashlib.sha256(password.encode()).hexdigest()
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def check_password() -> bool:
|
| 19 |
+
"""
|
| 20 |
+
Show login form and verify password.
|
| 21 |
+
|
| 22 |
+
Returns True if password is correct, False otherwise.
|
| 23 |
+
|
| 24 |
+
Configure password in Streamlit secrets:
|
| 25 |
+
[auth]
|
| 26 |
+
password = "your-secure-password"
|
| 27 |
+
|
| 28 |
+
Or set multiple users:
|
| 29 |
+
[auth]
|
| 30 |
+
passwords = { admin = "admin123", user1 = "pass123" }
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
def password_entered():
|
| 34 |
+
"""Check if entered password is correct."""
|
| 35 |
+
# Get password(s) from secrets
|
| 36 |
+
if "auth" in st.secrets:
|
| 37 |
+
# Check single password
|
| 38 |
+
if "password" in st.secrets["auth"]:
|
| 39 |
+
if hmac.compare_digest(
|
| 40 |
+
st.session_state["password"],
|
| 41 |
+
st.secrets["auth"]["password"]
|
| 42 |
+
):
|
| 43 |
+
st.session_state["authenticated"] = True
|
| 44 |
+
st.session_state["username"] = "user"
|
| 45 |
+
del st.session_state["password"]
|
| 46 |
+
return
|
| 47 |
+
|
| 48 |
+
# Check multiple users
|
| 49 |
+
if "passwords" in st.secrets["auth"]:
|
| 50 |
+
username = st.session_state.get("username_input", "")
|
| 51 |
+
password = st.session_state.get("password", "")
|
| 52 |
+
|
| 53 |
+
passwords = st.secrets["auth"]["passwords"]
|
| 54 |
+
if username in passwords and hmac.compare_digest(
|
| 55 |
+
password, passwords[username]
|
| 56 |
+
):
|
| 57 |
+
st.session_state["authenticated"] = True
|
| 58 |
+
st.session_state["username"] = username
|
| 59 |
+
del st.session_state["password"]
|
| 60 |
+
return
|
| 61 |
+
|
| 62 |
+
st.session_state["authenticated"] = False
|
| 63 |
+
st.session_state["password_incorrect"] = True
|
| 64 |
+
|
| 65 |
+
# Check if already authenticated
|
| 66 |
+
if st.session_state.get("authenticated", False):
|
| 67 |
+
return True
|
| 68 |
+
|
| 69 |
+
# Show login form
|
| 70 |
+
st.markdown("""
|
| 71 |
+
<style>
|
| 72 |
+
.login-container {
|
| 73 |
+
max-width: 400px;
|
| 74 |
+
margin: 100px auto;
|
| 75 |
+
padding: 40px;
|
| 76 |
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
|
| 77 |
+
border-radius: 15px;
|
| 78 |
+
box-shadow: 0 10px 40px rgba(0,0,0,0.3);
|
| 79 |
+
}
|
| 80 |
+
.login-title {
|
| 81 |
+
text-align: center;
|
| 82 |
+
color: #4ECDC4;
|
| 83 |
+
font-size: 2em;
|
| 84 |
+
margin-bottom: 10px;
|
| 85 |
+
}
|
| 86 |
+
.login-subtitle {
|
| 87 |
+
text-align: center;
|
| 88 |
+
color: #8b949e;
|
| 89 |
+
margin-bottom: 30px;
|
| 90 |
+
}
|
| 91 |
+
</style>
|
| 92 |
+
""", unsafe_allow_html=True)
|
| 93 |
+
|
| 94 |
+
col1, col2, col3 = st.columns([1, 2, 1])
|
| 95 |
+
|
| 96 |
+
with col2:
|
| 97 |
+
st.markdown('<div class="login-title">π₯ SPARKNET</div>', unsafe_allow_html=True)
|
| 98 |
+
st.markdown('<div class="login-subtitle">Document Intelligence Platform</div>', unsafe_allow_html=True)
|
| 99 |
+
|
| 100 |
+
st.markdown("---")
|
| 101 |
+
|
| 102 |
+
# Check if we have multi-user setup
|
| 103 |
+
has_multi_user = (
|
| 104 |
+
"auth" in st.secrets and
|
| 105 |
+
"passwords" in st.secrets["auth"]
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
if has_multi_user:
|
| 109 |
+
st.text_input(
|
| 110 |
+
"Username",
|
| 111 |
+
key="username_input",
|
| 112 |
+
placeholder="Enter username"
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
st.text_input(
|
| 116 |
+
"Password",
|
| 117 |
+
type="password",
|
| 118 |
+
key="password",
|
| 119 |
+
placeholder="Enter password",
|
| 120 |
+
on_change=password_entered
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
if st.button("π Login", type="primary", use_container_width=True):
|
| 124 |
+
password_entered()
|
| 125 |
+
|
| 126 |
+
if st.session_state.get("password_incorrect", False):
|
| 127 |
+
st.error("π Incorrect password. Please try again.")
|
| 128 |
+
|
| 129 |
+
st.markdown("---")
|
| 130 |
+
st.caption("Contact administrator for access credentials.")
|
| 131 |
+
|
| 132 |
+
return False
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def logout():
|
| 136 |
+
"""Log out the current user."""
|
| 137 |
+
st.session_state["authenticated"] = False
|
| 138 |
+
st.session_state["username"] = None
|
| 139 |
+
st.rerun()
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def get_current_user() -> Optional[str]:
|
| 143 |
+
"""Get the current logged-in username."""
|
| 144 |
+
return st.session_state.get("username")
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def require_auth(func):
|
| 148 |
+
"""Decorator to require authentication for a page."""
|
| 149 |
+
def wrapper(*args, **kwargs):
|
| 150 |
+
if check_password():
|
| 151 |
+
return func(*args, **kwargs)
|
| 152 |
+
return wrapper
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def show_logout_button():
|
| 156 |
+
"""Show logout button in sidebar."""
|
| 157 |
+
if st.session_state.get("authenticated", False):
|
| 158 |
+
with st.sidebar:
|
| 159 |
+
st.markdown("---")
|
| 160 |
+
user = get_current_user()
|
| 161 |
+
st.caption(f"Logged in as: **{user}**")
|
| 162 |
+
if st.button("πͺ Logout", use_container_width=True):
|
| 163 |
+
logout()
|
demo/pages/1_π¬_Live_Processing.py
CHANGED
|
@@ -32,6 +32,12 @@ from rag_config import (
|
|
| 32 |
|
| 33 |
st.set_page_config(page_title="Live Processing - SPARKNET", page_icon="π¬", layout="wide")
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# Custom CSS
|
| 36 |
st.markdown("""
|
| 37 |
<style>
|
|
|
|
| 32 |
|
| 33 |
st.set_page_config(page_title="Live Processing - SPARKNET", page_icon="π¬", layout="wide")
|
| 34 |
|
| 35 |
+
# Authentication
|
| 36 |
+
from auth import check_password, show_logout_button
|
| 37 |
+
if not check_password():
|
| 38 |
+
st.stop()
|
| 39 |
+
show_logout_button()
|
| 40 |
+
|
| 41 |
# Custom CSS
|
| 42 |
st.markdown("""
|
| 43 |
<style>
|
demo/pages/2_π¬_Interactive_RAG.py
CHANGED
|
@@ -234,6 +234,12 @@ st.set_page_config(
|
|
| 234 |
layout="wide"
|
| 235 |
)
|
| 236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
# Custom CSS
|
| 238 |
st.markdown("""
|
| 239 |
<style>
|
|
|
|
| 234 |
layout="wide"
|
| 235 |
)
|
| 236 |
|
| 237 |
+
# Authentication
|
| 238 |
+
from auth import check_password, show_logout_button
|
| 239 |
+
if not check_password():
|
| 240 |
+
st.stop()
|
| 241 |
+
show_logout_button()
|
| 242 |
+
|
| 243 |
# Custom CSS
|
| 244 |
st.markdown("""
|
| 245 |
<style>
|
demo/pages/3_π_Document_Comparison.py
CHANGED
|
@@ -28,6 +28,12 @@ from rag_config import (
|
|
| 28 |
|
| 29 |
st.set_page_config(page_title="Document Comparison - SPARKNET", page_icon="π", layout="wide")
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# Custom CSS
|
| 32 |
st.markdown("""
|
| 33 |
<style>
|
|
|
|
| 28 |
|
| 29 |
st.set_page_config(page_title="Document Comparison - SPARKNET", page_icon="π", layout="wide")
|
| 30 |
|
| 31 |
+
# Authentication
|
| 32 |
+
from auth import check_password, show_logout_button
|
| 33 |
+
if not check_password():
|
| 34 |
+
st.stop()
|
| 35 |
+
show_logout_button()
|
| 36 |
+
|
| 37 |
# Custom CSS
|
| 38 |
st.markdown("""
|
| 39 |
<style>
|
demo/pages/4_π―_Evidence_Viewer.py
CHANGED
|
@@ -26,6 +26,12 @@ from rag_config import (
|
|
| 26 |
|
| 27 |
st.set_page_config(page_title="Evidence Viewer - SPARKNET", page_icon="π―", layout="wide")
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
# Custom CSS with confidence-based colors
|
| 30 |
st.markdown("""
|
| 31 |
<style>
|
|
|
|
| 26 |
|
| 27 |
st.set_page_config(page_title="Evidence Viewer - SPARKNET", page_icon="π―", layout="wide")
|
| 28 |
|
| 29 |
+
# Authentication
|
| 30 |
+
from auth import check_password, show_logout_button
|
| 31 |
+
if not check_password():
|
| 32 |
+
st.stop()
|
| 33 |
+
show_logout_button()
|
| 34 |
+
|
| 35 |
# Custom CSS with confidence-based colors
|
| 36 |
st.markdown("""
|
| 37 |
<style>
|
demo/pages/5_π_Document_Viewer.py
CHANGED
|
@@ -37,6 +37,12 @@ st.set_page_config(
|
|
| 37 |
layout="wide"
|
| 38 |
)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# Custom CSS
|
| 41 |
st.markdown("""
|
| 42 |
<style>
|
|
|
|
| 37 |
layout="wide"
|
| 38 |
)
|
| 39 |
|
| 40 |
+
# Authentication
|
| 41 |
+
from auth import check_password, show_logout_button
|
| 42 |
+
if not check_password():
|
| 43 |
+
st.stop()
|
| 44 |
+
show_logout_button()
|
| 45 |
+
|
| 46 |
# Custom CSS
|
| 47 |
st.markdown("""
|
| 48 |
<style>
|