How taha-ter/injury_recovery_model works
Project type and purpose
• This is a full-stack, monolithic web application built with Python/Flask that serves a machine-learning model for predicting recovery time after an injury.
• The README confirms its goal: ingest historical injury data, train a predictive model, and expose visualizations and predictions via a web UI.
File structure
Top-level:
• application.py – the Flask app entry point (routes, session management, model inference).
• train_model.py – script to preprocess data (injury1.csv), train the ML pipeline, and dump artifacts (preprocessor.pkl, recovery_model.pkl).
• injury_recovery_model.pkl – a bundled model (or wrapper) for inference.
• requirements.txt – Python dependencies.
injury_recovery_model/
• flask_session/ – on-disk session store.
• static/ – CSS, JS, images, and graph scripts (pie.js, graph.js, jquery.js).
• templates/ – HTML templates (layout.html, index.html; external-page subfolder for injuries.html, injury_recover.html).
README for additional insights
• No explicit architecture section, but mentions Data Analysis, Predictive Modeling, and Visualization as three core capabilities.
• No external services (e.g., databases or message queues) are referenced—sessions and model artifacts are file-based.
Main components & their relationships
a. Frontend layer (Client Browser):
– HTML templates (layout, index, external pages)
– Static assets (CSS styling, JavaScript charting libraries)
b. Web/API layer (Flask app):
– application.py: HTTP endpoints for pages, form submissions, AJAX calls for charts.
– Flask-Session: persistent session storage in the flask_session directory.
c. Model layer (ML artifacts):
– Preprocessor (preprocessor.pkl) transforms user inputs into feature vectors.
– RecoveryModel (recovery_model.pkl) generates the prediction.
– Optionally an aggregated bundle (injury_recovery_model.pkl).
– train_model.py is a standalone pipeline that reads injury1.csv, generates these artifacts.
d. Data layer (for training):
– Raw data file (injury1.csv).
e. (Optional) Dependency layer:
– Python libraries (Flask, scikit-learn, pandas, etc. defined in requirements.txt).
Interactions:
• User → Browser → HTTP GET/POST → Flask → loads pickle → predicts → Flask → renders HTML/JSON → Browser
• Admin/Dev → CLI → python train_model.py → reads CSV → writes new .pkl artifacts
• Flask-Session intercepts requests to load/store session data on disk.
Architectural patterns & design principles
• MVC-style separation: Templates (View), application.py (Controller), model artifacts (Model).
• Three-tier web application: client, server, model/data.
• File-based session management (no external Redis/DB).
• Reusable training pipeline decoupled from serving code.