This repository contains a Flask web application for:
git clone https://github.com/adityarana-ar/Flask-webapp-ML.git
cd Flask-webapp-ML
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
/SP500:python generate_forecasts.py
Otherwise the background thread/service will begin generating after first start (can take a long time).
python main.py
Go to http://127.0.0.1:5000
/SP500 to view cached forecasts (next-day predicted close) and current market prices.forecast_data/predictions/ and does NOT trigger heavy model retraining.python generate_forecasts.py or wait for the background update to complete.A lightweight scheduler runs inside the Flask process (background thread) and checks hourly whether forecasts should be regenerated (once per trading day after market close).
For production you should externalize this using one of:
# Run at 22:00 UTC (after US market close) daily Mon-Fri
0 22 * * 1-5 /path/to/venv/bin/python /path/to/app/generate_forecasts.py >> /var/log/sp500_forecasts.log 2>&1
sp500-forecaster.servicesp500-forecaster.timer OR keep service always-on and let internal thread handle scheduling./etc/systemd/system/sp500-forecaster.timer):[Unit]
Description=Daily S&P 500 Forecast Generation Timer
[Timer]
OnCalendar=Mon..Fri 22:00
Persistent=true
[Install]
WantedBy=timers.target
Enable and start:
sudo systemctl enable sp500-forecaster.service
sudo systemctl enable sp500-forecaster.timer
sudo systemctl start sp500-forecaster.service
sudo systemctl start sp500-forecaster.timer
forecast_data/models/*.h5forecast_data/scalers/*.pklforecast_data/predictions/*_forecast.csvforecast_data/forecast_summary.jsonforecast_data/last_update.jsonstatic/Image/gunicorn -w 2 -b 0.0.0.0:8000 main:app
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
Create a Dockerfile (not yet included) for reproducible builds if containerizing. Example base:
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:8000", "main:app"]
SP500Forecaster.prepare_data for empty DataFrame handling.get_all_forecasts() returns only existing CSVs.Educational use only.
20 commits
HTML
37.4%
Python
30.9%
TypeScript
21.1%
Jupyter Notebook
8.4%
This repository contains a Flask web application for:
git clone https://github.com/adityarana-ar/Flask-webapp-ML.git
cd Flask-webapp-ML
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
/SP500:python generate_forecasts.py
Otherwise the background thread/service will begin generating after first start (can take a long time).
python main.py
Go to http://127.0.0.1:5000
/SP500 to view cached forecasts (next-day predicted close) and current market prices.forecast_data/predictions/ and does NOT trigger heavy model retraining.python generate_forecasts.py or wait for the background update to complete.A lightweight scheduler runs inside the Flask process (background thread) and checks hourly whether forecasts should be regenerated (once per trading day after market close).
For production you should externalize this using one of:
# Run at 22:00 UTC (after US market close) daily Mon-Fri
0 22 * * 1-5 /path/to/venv/bin/python /path/to/app/generate_forecasts.py >> /var/log/sp500_forecasts.log 2>&1
sp500-forecaster.servicesp500-forecaster.timer OR keep service always-on and let internal thread handle scheduling./etc/systemd/system/sp500-forecaster.timer):[Unit]
Description=Daily S&P 500 Forecast Generation Timer
[Timer]
OnCalendar=Mon..Fri 22:00
Persistent=true
[Install]
WantedBy=timers.target
Enable and start:
sudo systemctl enable sp500-forecaster.service
sudo systemctl enable sp500-forecaster.timer
sudo systemctl start sp500-forecaster.service
sudo systemctl start sp500-forecaster.timer
forecast_data/models/*.h5forecast_data/scalers/*.pklforecast_data/predictions/*_forecast.csvforecast_data/forecast_summary.jsonforecast_data/last_update.jsonstatic/Image/gunicorn -w 2 -b 0.0.0.0:8000 main:app
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
Create a Dockerfile (not yet included) for reproducible builds if containerizing. Example base:
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:8000", "main:app"]
SP500Forecaster.prepare_data for empty DataFrame handling.get_all_forecasts() returns only existing CSVs.Educational use only.
20 commits
HTML
37.4%
Python
30.9%
TypeScript
21.1%
Jupyter Notebook
8.4%