File size: 2,838 Bytes
9207866 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | # Docker Build and Run Script
# Builds the Docker image and runs the container
Write-Host "Intent Classification API - Docker Deployment" -ForegroundColor Cyan
Write-Host "==============================================" -ForegroundColor Cyan
Write-Host ""
# Check if model exists
if (-not (Test-Path "finetuned_intent_falconsai")) {
Write-Host "ERROR: Model directory 'finetuned_intent_falconsai' not found!" -ForegroundColor Red
Write-Host "Please run the training script first:" -ForegroundColor Yellow
Write-Host " python fine-tuning-falcon-ai.py" -ForegroundColor Yellow
exit 1
}
Write-Host "✓ Model directory found" -ForegroundColor Green
Write-Host ""
# Build Docker image
Write-Host "Building Docker image..." -ForegroundColor Cyan
docker build -t intent-classifier:latest .
if ($LASTEXITCODE -ne 0) {
Write-Host "✗ Docker build failed" -ForegroundColor Red
exit 1
}
Write-Host "✓ Docker image built successfully" -ForegroundColor Green
Write-Host ""
# Stop and remove existing container if running
Write-Host "Checking for existing container..." -ForegroundColor Cyan
$existingContainer = docker ps -a -q -f name=intent-api
if ($existingContainer) {
Write-Host "Stopping and removing existing container..." -ForegroundColor Yellow
docker stop intent-api
docker rm intent-api
}
# Run the container
Write-Host "Starting container..." -ForegroundColor Cyan
docker run -d -p 8000:8000 --name intent-api intent-classifier:latest
if ($LASTEXITCODE -eq 0) {
Write-Host "✓ Container started successfully" -ForegroundColor Green
Write-Host ""
Write-Host "API is running at: http://localhost:8000" -ForegroundColor Yellow
Write-Host "Interactive docs: http://localhost:8000/docs" -ForegroundColor Yellow
Write-Host ""
Write-Host "Useful commands:" -ForegroundColor Cyan
Write-Host " View logs: docker logs -f intent-api" -ForegroundColor Gray
Write-Host " Stop: docker stop intent-api" -ForegroundColor Gray
Write-Host " Restart: docker restart intent-api" -ForegroundColor Gray
Write-Host " Remove: docker rm -f intent-api" -ForegroundColor Gray
Write-Host ""
Write-Host "Waiting for API to be ready..." -ForegroundColor Cyan
Start-Sleep -Seconds 5
# Test health endpoint
try {
$response = Invoke-RestMethod -Uri "http://localhost:8000/health" -Method Get -TimeoutSec 10
Write-Host "✓ API is healthy and ready!" -ForegroundColor Green
Write-Host ($response | ConvertTo-Json)
} catch {
Write-Host "⚠ API is starting... Check logs with: docker logs -f intent-api" -ForegroundColor Yellow
}
} else {
Write-Host "✗ Failed to start container" -ForegroundColor Red
exit 1
}
|