#!/bin/bash
# Download Flux Schnell model (~12 GB) and start mflux-service.
# Schedule via: at 23:30 < scripts/mflux-download-model.sh
# Or:  echo "bash /Users/benjaminadmin/Projekte/breakpilot-lehrer/scripts/mflux-download-model.sh" | at 23:30

LOG="/tmp/mflux-download.log"
VENV="$HOME/mflux-env"
SCRIPT="$HOME/Projekte/breakpilot-lehrer/scripts/mflux-service.py"

echo "$(date): Starting Flux Schnell model download..." >> "$LOG"

# Generate a test image to trigger model download
"$VENV/bin/mflux-generate" \
  --model schnell \
  --prompt "test" \
  --steps 2 \
  --width 256 --height 256 \
  -o /tmp/mflux-test.png \
  >> "$LOG" 2>&1

echo "$(date): Model download complete. Starting mflux-service..." >> "$LOG"

# Start the service
nohup "$VENV/bin/python" "$SCRIPT" >> "$LOG" 2>&1 &

echo "$(date): mflux-service started (PID $!)." >> "$LOG"
