api / DEPLOY.md
safraeli's picture
Deploy: 2026 sensor migration + redesign + bucket B endpoints
13fc29d verified
|
Raw History Blame Contribute Delete
3.2 kB

ש# Deploy Streamlit app (free – Streamlit Community Cloud)

1. Prerequisites

  • App code in a public GitHub repo (e.g. solarwine-ai/Baseline).
  • A Streamlit Community Cloud account (sign in with GitHub).
  • sensors_wide_sample.csv committed under Data/Seymour/ (already in the repo).

2. Deploy steps

  1. Go to https://share.streamlit.io and sign in with GitHub.

  2. Click "New app".

  3. Set:

    • Repository: solarwine-ai/Baseline (or your fork).
    • Branch: main.
    • Main file path: app.py.
  4. Click "Advanced settings" and set:

    • Python version: 3.11 (or match your local).
    • Leave Requirements file as requirements.txt (repo root).
  5. Under Secrets, add your IMS API token so the app can fetch IMS data:

    IMS_API_TOKEN = "your-ims-api-token-here"
    

    Streamlit Cloud injects secrets as environment variables; the app reads IMS_API_TOKEN from the environment via os.environ.

  6. Click "Deploy". The first build may take a few minutes.

3. How data works on Community Cloud

  • Sensor data (Stage 1): The full sensors_wide.csv (982 MB) is gitignored. Instead, a trimmed sensors_wide_sample.csv (~2.7 MB, Stage 1 columns only, growing season May-Sep) is committed. The app automatically falls back to the sample when the full file is absent — no code changes needed.

  • IMS data (Stage 2): Click Download IMS 2024–2025 in the sidebar (requires IMS_API_TOKEN in Secrets), then Run Stage 2. IMS data is fetched at runtime; free-tier memory and CPU limits apply to very large or long-running fetches.

  • Secrets: Never commit .env or real tokens. Use only the Secrets field in the Streamlit Cloud app settings.

4. Regenerating the sample CSV locally

If you update the full sensor data and need to refresh the sample:

python -m scripts.create_sample_data

This reads sensors_wide.csv, extracts Stage 1 columns for May-Sep, and writes sensors_wide_sample.csv. Commit the updated sample.

5. Configuration files

  • .streamlit/config.toml — sets headless = true and light theme for Cloud.
  • requirements.txt — Python dependencies (already in repo root).
  • No packages.txt needed (no OS-level dependencies).

6. Chronos-2 long training (local)

To run LoRA fine-tuning with a large context window until results converge (single run, tuned for 32 GB RAM / 10 CPU cores):

cd /path/to/Baseline
PYTHONPATH=. conda run -n solarwine python scripts/run_chronos_long_training.py \
  --device cpu \
  --context-days 28 \
  --num-steps 4000 \
  --batch-size 16
  • Output: Checkpoints in outputs/chronos_finetuned_long/; benchmark row lora / all appended to outputs/chronos_benchmark.csv; sample plot outputs/chronos_forecast_sample.png.
  • Convergence: Chronos does not support resuming LoRA across multiple fit() calls; use one large --num-steps (e.g. 4000–6000). Training uses built-in validation; adjust --learning-rate (default 1e-5) if needed.
  • Resources: Script sets OMP_NUM_THREADS from CPU count; use --batch-size 8 on lower memory.