|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -# Define the default port |
| 3 | +# Set the default port |
4 | 4 | PORT=5000
|
5 | 5 |
|
6 | 6 | # Check if AIP_MODE is set and adjust the port for Vertex AI
|
7 | 7 | if [[ ! -z "${AIP_MODE}" ]]; then
|
8 | 8 | PORT=${AIP_HTTP_PORT}
|
9 | 9 | fi
|
10 | 10 |
|
11 |
| -# Check if HF_MODEL_DIR is set and if not skip installing custom dependencies |
| 11 | +# Check that only one of HF_MODEL_ID or HF_MODEL_DIR is provided |
| 12 | +if [[ ! -z "${HF_MODEL_ID}" && ! -z "${HF_MODEL_DIR}" ]]; then |
| 13 | + echo "Error: Both HF_MODEL_ID and HF_MODEL_DIR are set. Please provide only one." |
| 14 | + exit 1 |
| 15 | +elif [[ -z "${HF_MODEL_ID}" && -z "${HF_MODEL_DIR}" ]]; then |
| 16 | + echo "Error: Neither HF_MODEL_ID nor HF_MODEL_DIR is set. Please provide one of them." |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +# If HF_MODEL_ID is provided, download handler.py and requirements.txt if available |
| 21 | +if [[ ! -z "${HF_MODEL_ID}" ]]; then |
| 22 | + filename=${HF_DEFAULT_PIPELINE_NAME:-handler.py} |
| 23 | + revision=${HF_REVISION:-main} |
| 24 | + |
| 25 | + echo "Downloading $filename for model ${HF_MODEL_ID}" |
| 26 | + huggingface-cli download ${HF_MODEL_ID} "$filename" --revision "$revision" --local-dir /tmp |
| 27 | + |
| 28 | + # Check if handler.py was downloaded successfully |
| 29 | + if [ -f "/tmp/$filename" ]; then |
| 30 | + echo "$filename downloaded successfully, checking if there's a requirements.txt file..." |
| 31 | + rm /tmp/$filename |
| 32 | + |
| 33 | + # Attempt to download requirements.txt |
| 34 | + echo "Downloading requirements.txt for model ${HF_MODEL_ID}" |
| 35 | + huggingface-cli download "${HF_MODEL_ID}" requirements.txt --revision "$revision" --local-dir /tmp |
| 36 | + |
| 37 | + # Check if requirements.txt was downloaded successfully |
| 38 | + if [ -f "/tmp/requirements.txt" ]; then |
| 39 | + echo "requirements.txt downloaded successfully, now installing the dependencies..." |
| 40 | + |
| 41 | + # Install dependencies |
| 42 | + pip install -r /tmp/requirements.txt --no-cache-dir |
| 43 | + rm /tmp/requirements.txt |
| 44 | + else |
| 45 | + echo "${HF_MODEL_ID} with revision $revision contains a custom handler at $filename but doesn't contain a requirements.txt file, so skipping downloading and installing extra requirements from it." |
| 46 | + fi |
| 47 | + else |
| 48 | + echo "${HF_MODEL_ID} with revision $revision doesn't contain a $filename file, so skipping download." |
| 49 | + fi |
| 50 | +fi |
| 51 | + |
| 52 | +# If HF_MODEL_DIR is provided, check for requirements.txt and install dependencies if available |
12 | 53 | if [[ ! -z "${HF_MODEL_DIR}" ]]; then
|
13 | 54 | # Check if requirements.txt exists and if so install dependencies
|
14 | 55 | if [ -f "${HF_MODEL_DIR}/requirements.txt" ]; then
|
|
0 commit comments