Spaces:
Runtime error
Runtime error
File size: 5,198 Bytes
0f60365 1923610 0f60365 1923610 0f60365 1923610 0f60365 1923610 0f60365 1923610 0f60365 1923610 0f60365 1923610 0f60365 1923610 0f60365 1923610 0f60365 1923610 0f60365 1923610 0f60365 1923610 0f60365 1923610 0f60365 1923610 0f60365 |
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
#!/bin/bash
# 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
|