Files
predictive_analysis/app.py
T
2025-09-28 00:37:22 +03:00

117 lines
3.3 KiB
Python

"""
Main Streamlit application for Student Success Predictor
Modular version with separated components
"""
import streamlit as st
import sys
from pathlib import Path
# Add src directory to path for imports
src_path = Path(__file__).parent
sys.path.append(str(src_path))
from src.config.theme import ROSE_PINE_THEME, PAGE_CONFIG, APP_TITLE, APP_SUBTITLE
from src.config.mappings import create_feature_mappings
from src.utils.model_utils import load_model_and_info
from src.components.form_components import (
render_preset_selector,
render_personal_info_section,
render_academic_background_section,
render_family_background_section,
render_financial_social_section,
render_academic_performance_section,
render_economic_indicators_section
)
from src.components.prediction_components import (
render_prediction_section,
render_model_info_sidebar,
render_export_section,
render_footer
)
def apply_theme():
"""Apply the Rose Pine dark theme"""
st.markdown(ROSE_PINE_THEME, unsafe_allow_html=True)
def render_header():
"""Render the main application header"""
st.markdown(f'<h1 class="main-header">{APP_TITLE}</h1>', unsafe_allow_html=True)
st.markdown(f'<p class="subtitle">{APP_SUBTITLE}</p>', unsafe_allow_html=True)
def collect_user_input():
"""Collect all user input from the sidebar form"""
feature_maps = create_feature_mappings()
with st.sidebar:
# Preset selector
preset = render_preset_selector()
# Personal information
personal_info = render_personal_info_section(preset, feature_maps)
# Academic background
academic_bg = render_academic_background_section(preset, feature_maps)
# Family background
family_bg = render_family_background_section(feature_maps)
# Financial and social factors
financial_social = render_financial_social_section()
# Academic performance
academic_performance = render_academic_performance_section(preset)
# Economic indicators
economic_indicators = render_economic_indicators_section()
# Combine all input data
user_input = {
**personal_info,
**academic_bg,
**family_bg,
**financial_social,
**academic_performance,
**economic_indicators
}
return user_input
def main():
"""Main Streamlit application"""
# Configure page
st.set_page_config(**PAGE_CONFIG)
# Apply theme
apply_theme()
# Load model and preprocessing info
model, preprocessing_info, feature_names = load_model_and_info()
# Render header
render_header()
# Collect user input
user_input = collect_user_input()
# Main content area
col1, col2 = st.columns([2, 1])
with col1:
st.markdown('<h2 class="sub-header">Prediction Results</h2>', unsafe_allow_html=True)
# Render prediction section
render_prediction_section(model, preprocessing_info, user_input)
with col2:
# Render model info and validation
render_model_info_sidebar(user_input)
# Render export section
render_export_section(user_input)
# Render footer
render_footer()
if __name__ == "__main__":
main()