#!/bin/bash
# ============================================================
# AI4EVER Unified Installer (Imagery + Tabular)
# ============================================================

# Determine where this script is located
DIR="$(cd "$(dirname "$0")" && pwd)"
echo "Installing packages from: $DIR"

# Choose an available python (system or conda)
PYTHON_CMD=$(which python3 || which python)
echo "Using Python at: $PYTHON_CMD"

# Upgrade pip to latest version
$PYTHON_CMD -m pip install --upgrade pip setuptools wheel

# ---- Step 1. Install TensorFlow ----
if [ -f "$DIR/tensorflow-2.4.1-py3-none-any.whl" ]; then
    echo "Installing TensorFlow from local wheel..."
    $PYTHON_CMD -m pip install "$DIR/tensorflow-2.4.1-py3-none-any.whl"
else
    echo "TensorFlow wheel not found locally — installing from PyPI..."
    $PYTHON_CMD -m pip install tensorflow==2.4.1
fi

# ---- Step 2. Install all remaining dependencies ----
if [ -f "$DIR/requirements.txt" ]; then
    echo "Installing other required Python packages..."
    $PYTHON_CMD -m pip install -r "$DIR/requirements.txt"
else
    echo "Error: requirements.txt not found at $DIR"
    exit 1
fi

echo "AI4EVER environment setup complete!"
