Setup & Configuration
Prerequisites
- Python 3.13+
- uv (Python package manager)
- TensorFlow-compatible system
- GPU (optional, for faster inference)
Installation
cd services/ai_service
uv syncEnvironment Variables
Required
MODEL_DIRECTORY: Path to model files (required)
Optional
USE_GPU: Enable GPU inference (default:true)LOG_LEVEL: Logging level (default:info)PORT: Service port (default:8080)
Example .env
MODEL_DIRECTORY=/models
USE_GPU=true
LOG_LEVEL=info
PORT=8080Model Directory Structure
Models should be stored in the directory specified by MODEL_DIRECTORY:
models/
βββ <model_name>/
βββ model/
β βββ best_model.h5
βββ mlb.pkl # Disease labels
βββ model_params.pkl # Model configuration
βββ continuous_mean.pkl # Metadata field averages
βββ scaler.pkl # MinMax scaler
βββ raw_list_of_field.pkl # Metadata field listRunning the Service
Development
uv run uvicorn src.main:app --reload --port 8080Production
uv run uvicorn src.main:app --host 0.0.0.0 --port 8080 --workers 4With GPU
Ensure CUDA is installed and configured:
# Check GPU availability
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
# Run service
USE_GPU=true uv run uvicorn src.main:app --port 8080CPU-Only Mode
Force CPU inference even if GPU is available:
USE_GPU=false uv run uvicorn src.main:app --port 8080Testing
# Run tests
uv run pytest
# Run with coverage
uv run pytest --cov=src --cov-report=html
# Test specific module
uv run pytest src/core/models/predictor_test.pyDeployment
Docker
Build and run with Docker:
docker build -t dermadetect-ai-service .
docker run -p 8080:8080 \
-v /path/to/models:/models \
-e MODEL_DIRECTORY=/models \
dermadetect-ai-serviceKubernetes
Deploy to Kubernetes:
kubectl apply -f k8s/ai-service-deployment.yaml
kubectl apply -f k8s/ai-service-service.yamlScale replicas for higher throughput:
kubectl scale deployment ai-service --replicas=5Health Check
Verify the service is running:
curl http://localhost:8080/healthExpected response:
{
"status": "healthy",
"gpu_available": true,
"models_loaded": true
}Last updated on