TC-Brain-26 / app.py
aaliyahhasna's picture
Update app.py
82ce254 verified
Raw History Blame Contribute Delete
6.85 kB
"""
app.py — DOBI (Digital Organisational Brain & Insight)
====================================================================
WHAT THIS FILE IS: the main entry point. Hugging Face runs this file to
start the app. Everything the user sees begins here.
WHAT IT DOES: sets up the page, the sidebar (logo, navigation) and the
four screens — Ask, Library, What's missing, and Admin — and hands off to
the matching view in pages_ui.py. There is NO login: anyone with the link
can ask questions and browse. The Admin screen asks for a password before
it shows any add/edit/delete tools (see pages_ui.view_admin).
HOW IT FITS: pages_ui.py (screens) · search.py (answers, via pages_ui) ·
supabase_client.py (database connection). The look comes from
.streamlit/config.toml (Think City colours, light theme).
FOR WHOEVER TAKES OVER: admin write access is protected by a single
password stored as the ADMIN_PASSWORD Space secret. auth.py is unused.
====================================================================
"""
import os
import streamlit as st
from pages_ui import view_search, view_library, view_gaps, view_admin
_ICON = os.path.join(os.path.dirname(__file__), "dobi-icon.png")
st.set_page_config(
page_title="DOBI",
page_icon=_ICON if os.path.exists(_ICON) else "🧺",
layout="wide", # room for the sources rail; widths capped in CSS
initial_sidebar_state="expanded",
)
# ---- Look and feel (Think City palette; one bold element: the facade band) ----
st.markdown(
"""
<style>
@import url('https://fonts.googleapis.com/css2?family=Schibsted+Grotesk:wght@400;600&family=Source+Serif+4:wght@400;600&display=swap');
html, body, [class*="css"], .stMarkdown, .stButton button, input, textarea { font-family:'Schibsted Grotesk', Arial, sans-serif; }
h1, h2, h3, .stMarkdown h1, .stMarkdown h2, .stMarkdown h3 { font-family:'Source Serif 4', Georgia, serif !important; font-weight:400 !important; }
:root { --dobi-blue:#000F9F; --dobi-green:#00C08B; --dobi-grey:#E6E6E6; --dobi-muted:rgba(0,0,0,.62); }
.block-container { max-width: 70rem; padding-top: 2rem; }
/* Facade band with the shophouse arcade edge */
.st-key-dobi-band { background: var(--dobi-blue); padding: 3rem 2rem 0; gap: 1rem; }
.st-key-dobi-band .dobi-hero { color:#FFFFFF; font-family:'Source Serif 4', Georgia, serif; font-weight:400;
font-size: clamp(2.75rem, 6vw, 4rem); line-height:1.05; margin:0; padding:0; }
.st-key-dobi-band .dobi-try { color:rgba(255,255,255,.85); margin:.5rem 0 0; font-size:.9375rem; }
.st-key-dobi-band button { background:transparent; color:#FFFFFF; border:1px solid #FFFFFF; border-radius:.75rem;
min-height:2.75rem; height:100%; padding:.75rem 1rem; font-size:.9375rem; line-height:1.35;
justify-content:flex-start; text-align:left; white-space:normal; }
.st-key-dobi-band [data-testid="stHorizontalBlock"] { align-items:stretch; }
.st-key-dobi-band button:hover, .st-key-dobi-band button:focus-visible { background:#FFFFFF; color:var(--dobi-blue); }
.st-key-dobi-band button:focus-visible { outline:2px solid var(--dobi-green); outline-offset:2px; }
.st-key-dobi-band .dobi-arches { display:block; width:calc(100% + 4rem); margin:1.5rem -2rem 0; }
/* Did you know, recently added */
.dobi-dyk { font-family:'Source Serif 4', Georgia, serif; font-size:1.625rem; line-height:1.35; max-width:42rem; margin:0; }
.dobi-dyk-src, .dobi-meta { color:var(--dobi-muted); font-size:.9375rem; }
/* Lists on the Ask page: rows separated by thin rules */
.dobi-list { list-style:none; margin:0; padding:0; }
.dobi-list li { padding:.75rem 0; border-top:1px solid var(--dobi-grey); font-size:1.0625rem; line-height:1.4; }
.dobi-list li:last-child { border-bottom:1px solid var(--dobi-grey); }
.dobi-list a { color:#000000; text-decoration:underline; text-underline-offset:3px; }
.dobi-list .dobi-meta { display:block; margin-top:.2rem; }
.st-key-dobi-recent { gap:0; }
.st-key-dobi-another-fact button { background:transparent; border:none; box-shadow:none; padding:0; min-height:2.75rem;
color:var(--dobi-blue); text-decoration:underline; text-underline-offset:3px; }
.st-key-dobi-recent button { background:transparent; border:none; box-shadow:none; justify-content:flex-start; text-align:left; white-space:normal; min-height:2.75rem;
padding:.75rem 0; border-top:1px solid var(--dobi-grey); border-radius:0; font-size:1.0625rem; color:#000000; }
.st-key-dobi-recent button:hover { color:var(--dobi-blue); text-decoration:underline; }
/* Answers: serif reading text, small sans group headings */
[class*="st-key-answer-"] p, [class*="st-key-answer-"] li {
font-family:'Source Serif 4', Georgia, serif; font-size:1.25rem; line-height:1.65; }
[class*="st-key-answer-"] [data-testid="stMarkdownContainer"] > p:first-child { font-size:1.375rem; }
[class*="st-key-answer-"] h4 { font-family:'Schibsted Grotesk', Arial, sans-serif; font-size:1.0625rem;
font-weight:600; margin:1.5rem 0 .25rem; }
[class*="st-key-answer-"] a { white-space:nowrap; font-family:'Schibsted Grotesk', Arial, sans-serif; font-size:.85em; }
[data-testid="stChatMessage"] h3 { font-size:1.75rem; font-weight:400; }
/* While DOBI reads */
.dobi-reading { position:relative; padding-top:1.25rem; max-width:42rem; }
.dobi-progress { position:absolute; top:0; left:0; right:0; height:2px; background:var(--dobi-grey); overflow:hidden; }
.dobi-progress::after { content:""; position:absolute; top:0; height:2px; width:30%; background:var(--dobi-green);
animation:dobi-slide 1.6s ease-in-out infinite; }
@keyframes dobi-slide { from { left:-30%; } to { left:100%; } }
.dobi-label { color:var(--dobi-muted); font-size:.9375rem; margin:.25rem 0; }
.dobi-facts { position:relative; min-height:7.5rem; }
.dobi-fact { position:absolute; inset:0; }
.dobi-fact:only-child { position:static; }
.dobi-fact-text { font-family:'Source Serif 4', Georgia, serif; font-size:1.5rem; line-height:1.35; margin:0 0 .25rem; }
.dobi-fact-src { color:var(--dobi-muted); font-size:.9375rem; margin:0; }
@media (prefers-reduced-motion: reduce) { .dobi-progress::after { animation:none; left:0; width:100%; } }
</style>
""",
unsafe_allow_html=True,
)
# ---- Sidebar: identity, then navigation ----
with st.sidebar:
if os.path.exists(_ICON):
st.image(_ICON, width=56)
st.markdown("**DOBI** \nThink City's knowledge library")
st.divider()
pages = {
"": [
st.Page(view_search, title="Ask", icon=":material/search:", url_path="ask", default=True),
st.Page(view_library, title="Library", icon=":material/menu_book:", url_path="library"),
st.Page(view_gaps, title="What's missing", icon=":material/help_outline:", url_path="missing"),
],
"Manage": [
st.Page(view_admin, title="Admin", icon=":material/lock:", url_path="admin"),
],
}
st.navigation(pages, position="sidebar").run()