2026-05-07 15:42:29 +02:00

61 lines
1.7 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 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: 0rem; margin-top: -2rem; }
</style>
""",
unsafe_allow_html=True,
)
st.title("Lightweight code editor")
# 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":
render_editor()
elif st.session_state.get("radio_interface_options") == "Chat with AI Assistant":
render_chat()
if __name__ == "__main__":
main()