2026-05-25 19:02:20 +02:00

68 lines
2.0 KiB
Python

"""Entry point for the Streamlit app.
Runs with: streamlit run frontend/app.py
Responsibilities:
- Configure the page layout
- Inject global CSS tweaks
- Render the sidebar (navigation + file explorer)
- Delegate to the correct view (Chat or Code Editor) based on the radio selection
"""
import streamlit as st
import sys
from pathlib import Path
# Add the project root to sys.path so backend imports work regardless of
# where streamlit is launched from.
sys.path.insert(0, str(Path(__file__).parent.parent))
from backend.managers.debug_logger import get_logger
logger = get_logger(__name__)
from frontend.sidebar import render_sidebar
from frontend.editor import render_editor
from frontend.chat import render_chat
from frontend.state import init_state
# Initialise all session-state keys before any widget is rendered
init_state()
def main():
st.set_page_config(page_title="Lightweight code editor", layout="wide")
# Small spacing corrections applied globally:
# - Reduce the default top padding of the main content area
# - Pull the sidebar content up so the logo sits at the very top
st.markdown(
"""
<style>
.block-container { padding-top: 1rem; }
[data-testid="stSidebarContent"] { padding-top: 1rem; }
</style>
""",
unsafe_allow_html=True,
)
st.title("Lightweight code editor")
# REVIEW: redundant — init_state() is already called at module level (line 26) before main() runs;
# calling it again here is unnecessary since Streamlit reruns the whole module on each reload.
# Re-run init_state to cover any keys that might have been missed on cold start
init_state()
render_sidebar()
# Switch between the two main views based on the sidebar radio button
if st.session_state.get("radio_interface_options") == "Code Editor":
logger.info("Editor mode")
render_editor()
elif st.session_state.get("radio_interface_options") == "Chat with AI Assistant":
logger.info("Chat/Agent mode")
render_chat()
if __name__ == "__main__":
main()