#!/usr/bin/env bash # start.sh — Quick-start script for the HF CPU Image Generation API set -e VENV_DIR=".venv" echo "" echo "═══════════════════════════════════════════════════════════════" echo " HF CPU Image Generation API — Setup & Start" echo "═══════════════════════════════════════════════════════════════" echo "" # ── 1. Create virtualenv if needed ──────────────────────────────────────────── if [ ! -d "$VENV_DIR" ]; then echo "→ Creating Python virtualenv in $VENV_DIR ..." python3 -m venv "$VENV_DIR" fi source "$VENV_DIR/bin/activate" # ── 2. Install PyTorch (CPU-only wheel) ─────────────────────────────────────── if ! python -c "import torch" 2>/dev/null; then echo "→ Installing PyTorch (CPU-only) ..." pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu -q fi # ── 3. Install other dependencies ───────────────────────────────────────────── echo "→ Installing dependencies from requirements.txt ..." pip install -r requirements.txt -q # ── 4. Copy .env if not present ─────────────────────────────────────────────── if [ ! -f ".env" ]; then echo "→ Creating .env from .env.example ..." cp .env.example .env fi # ── 5. Start the API ────────────────────────────────────────────────────────── echo "" echo "→ Starting API on http://0.0.0.0:8000" echo " Swagger UI: http://localhost:8000/docs" echo " API health: http://localhost:8000/health" echo "" python -m uvicorn main:app --host 0.0.0.0 --port 8000 --workers 1