Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
56 lines (44 loc) · 1.61 KB
/
Copy pathapp.py
File metadata and controls
56 lines (44 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
Main application entry point for the Streamlit ChatBot.
Startup sequence
----------------
1. Configure the Python logging system (precise format with file + line info).
2. Initialize the SQLite database schema (idempotent).
3. Initialize Streamlit session state variables.
4. Render sidebar and chat UI components.
Run with:
streamlit run app.py
"""
# Standard library
import logging, traceback
# Third-party
import streamlit as st
# NOTE: Logging must be configured before any local module is imported
# This ensures every logger created by sub-modules uses the correct format.
from backend.logger import setup_logging
setup_logging(
level=logging.INFO,
# log_file="logs/chatbot.log", # to also write logs to a rotating file
)
# Local (imported after logging is configured)
from frontend.state import init_session_state
from frontend.ui import render_sidebar, render_chat
logger = logging.getLogger(__name__) # innitiate logging
def main() -> None:
"""
Initialize the application and render the Streamlit UI.
"""
try:
# Initialize the DB schema once at startup (CREATE TABLE IF NOT EXISTS)
from backend.db import init_db
init_db()
# Initialize session state (safe on every rerun, guards prevent overwrites)
init_session_state()
# Render the two top-level UI components
render_sidebar()
render_chat()
except Exception:
logger.critical("Application crashed:\n%s", traceback.format_exc())
st.error("A critical error occurred. Please check the terminal / console for details.")
if __name__ == "__main__":
main()