Spaces:
Runtime error
Runtime error
# Helper script for running the translations API with pure Docker commands | |
# (Alternative to docker-compose for environments that don't have it) | |
# Parse GPU flag | |
USE_GPU=false | |
if [[ "$*" == *"--gpu"* ]]; then | |
USE_GPU=true | |
fi | |
# Build the image | |
echo "Building mms-transcription image..." | |
# docker build --platform linux/amd64 -t mms-transcription . | |
# Function to get GPU arguments | |
get_gpu_args() { | |
if [ "$USE_GPU" = true ]; then | |
echo "--gpus all" | |
else | |
echo "" | |
fi | |
} | |
# Function to get GPU environment variables | |
get_gpu_env_vars() { | |
if [ "$USE_GPU" = true ]; then | |
echo "-e CUDA_VISIBLE_DEVICES=0 -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=compute,utility" | |
else | |
echo "" | |
fi | |
} | |
# Function to get memory arguments for large ML models | |
get_memory_args() { | |
echo "--shm-size=8g" | |
} | |
# Function to run for production | |
run_production() { | |
if [ "$USE_GPU" = true ]; then | |
echo "Starting translations API in production mode (with GPU support)..." | |
else | |
echo "Starting translations API in production mode (CPU only)..." | |
fi | |
docker run -d \ | |
--name translations_api \ | |
--platform linux/amd64 \ | |
$(get_memory_args) \ | |
$(get_gpu_args) \ | |
-p 7860:7860 \ | |
-p 5679:5678 \ | |
-v $(pwd)/server:/home/user/app/server \ | |
-v $(pwd)/server/models:/home/user/app/models \ | |
-e AWS_ACCESS_KEY_ID \ | |
-e AWS_SECRET_ACCESS_KEY \ | |
-e AWS_SESSION_TOKEN \ | |
-e API_LOG_LEVEL=INFO \ | |
$(get_gpu_env_vars) \ | |
mms-transcription | |
} | |
# Function to run for development | |
run_development() { | |
if [ "$USE_GPU" = true ]; then | |
echo "Starting translations API in development mode (with GPU support)..." | |
else | |
echo "Starting translations API in development mode (CPU only)..." | |
fi | |
# Remove existing container if it exists | |
echo "Removing existing translations_dev container if it exists..." | |
docker rm -f translations_dev 2>/dev/null || true | |
echo "Allocating 16GB memory for large ML model loading..." | |
echo "Running new translations_dev container" | |
docker run -it \ | |
--name translations_dev \ | |
--platform linux/amd64 \ | |
$(get_memory_args) \ | |
$(get_gpu_args) \ | |
-p 7860:7860 \ | |
-p 5679:5678 \ | |
-v $(pwd)/server:/home/user/app/server \ | |
-v $(pwd)/server/models:/home/user/app/models \ | |
-e AWS_ACCESS_KEY_ID \ | |
-e AWS_SECRET_ACCESS_KEY \ | |
-e AWS_SESSION_TOKEN \ | |
-e API_LOG_LEVEL=DEBUG \ | |
$(get_gpu_env_vars) \ | |
mms-transcription | |
} | |
# Function to run tests | |
run_tests() { | |
echo "Running tests..." | |
docker run --rm \ | |
--name translations_test \ | |
--platform linux/amd64 \ | |
-v $(pwd)/server:/home/user/app/server \ | |
-v $(pwd)/server/models:/home/user/app/models \ | |
-w /home/user/app \ | |
-e PYTHONPATH=/home/user/app \ | |
-e AWS_ACCESS_KEY_ID \ | |
-e AWS_SECRET_ACCESS_KEY \ | |
-e AWS_SESSION_TOKEN \ | |
mms-transcription \ | |
conda run --no-capture-output -n mms-transcription bash /home/user/app/server/run_tests.sh | |
} | |
# Function to run for HF Spaces-like deployment (no volume mounts) | |
run_deployment() { | |
if [ "$USE_GPU" = true ]; then | |
echo "Starting translations API in deployment mode (with GPU support, no volume mounts)..." | |
else | |
echo "Starting translations API in deployment mode (CPU only, no volume mounts)..." | |
fi | |
echo "Allocating 16GB memory for large ML model loading..." | |
docker run -d \ | |
--name translations_api_deploy \ | |
--platform linux/amd64 \ | |
$(get_memory_args) \ | |
$(get_gpu_args) \ | |
-p 7860:7860 \ | |
-e AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \ | |
-e AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \ | |
-e AWS_SESSION_TOKEN="${AWS_SESSION_TOKEN}" \ | |
-e API_LOG_LEVEL=INFO \ | |
$(get_gpu_env_vars) \ | |
mms-transcription | |
} | |
# Parse command line arguments | |
case "$1" in | |
"prod"|"production") | |
run_production | |
;; | |
"dev"|"development") | |
run_development | |
;; | |
"test"|"tests") | |
run_tests | |
;; | |
"deploy"|"deployment") | |
run_deployment | |
;; | |
*) | |
echo "Usage: $0 {prod|dev|test|deploy} [--gpu]" | |
echo "" | |
echo "Commands:" | |
echo " prod/production - Run in production mode with volume mounts" | |
echo " dev/development - Run in development mode (interactive)" | |
echo " test/tests - Run tests" | |
echo " deploy/deployment - Run in deployment mode (no volume mounts)" | |
echo "" | |
echo "Options:" | |
echo " --gpu - Enable GPU support (requires NVIDIA GPU and drivers)" | |
echo "" | |
echo "Examples:" | |
echo " $0 dev # Start development server (CPU only)" | |
echo " $0 dev --gpu # Start development server with GPU support" | |
echo " $0 prod # Start production server (CPU only)" | |
echo " $0 prod --gpu # Start production server with GPU support" | |
echo " $0 test # Run tests" | |
echo " $0 deploy --gpu # Start deployment server with GPU support" | |
exit 1 | |
;; | |
esac | |