|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +validate_access_token() { |
| 4 | + if [ -z "$CVAT_ACCESS_TOKEN" ]; then |
| 5 | + echo "Error: CVAT_ACCESS_TOKEN environment variable must be set." |
| 6 | + exit 1 |
| 7 | + fi |
| 8 | +} |
| 9 | + |
| 10 | +resolve_base_url() { |
| 11 | + if [ -z "$CVAT_BASE_URL" ]; then |
| 12 | + echo "Warning: CVAT_BASE_URL environment variable is missing, using https://app.cvat.ai as default." |
| 13 | + CVAT_BASE_URL="https://app.cvat.ai" |
| 14 | + fi |
| 15 | +} |
| 16 | + |
| 17 | +resolve_org_slug() { |
| 18 | + ORG_SLUG_ARGS=() |
| 19 | + if [ -z "$ORG_SLUG" ]; then |
| 20 | + echo "Warning: ORG_SLUG environment variable not found. Function will be registered only for your user." |
| 21 | + echo "ORG_SLUG must be the short name of the organization; it is the name displayed under your username when you switch to the organization in the CVAT UI." |
| 22 | + ORG_CURL_ARGS=(--data-urlencode "org=") |
| 23 | + else |
| 24 | + echo "Using organization: $ORG_SLUG" |
| 25 | + ORG_SLUG_ARGS=(--organization "$ORG_SLUG") |
| 26 | + ORG_CURL_ARGS=(--data-urlencode "org=$ORG_SLUG") |
| 27 | + fi |
| 28 | +} |
| 29 | + |
| 30 | +resolve_cuda() { |
| 31 | + if [ "$USE_CUDA" = "true" ]; then |
| 32 | + echo "Using CUDA! Please ensure that you are using proper image with CUDA support" |
| 33 | + USE_CUDA_ARGS=(-p device=str:cuda) |
| 34 | + else |
| 35 | + echo "Info: USE_CUDA environment variable not found. Model will run on CPU." |
| 36 | + fi |
| 37 | +} |
| 38 | + |
| 39 | +resolve_model_params() { |
| 40 | + if [ -z "$MODEL_CONFIG_PARAMS" ]; then |
| 41 | + echo "Warning: MODEL_CONFIG_PARAMS environment variable not found. Default model will be used: facebook/detr-resnet-50" |
| 42 | + MODEL_CONFIG_PARAMS="-p model=facebook/detr-resnet-50" |
| 43 | + MODEL="-p task=str:object-detection -p model=str:facebook/detr-resnet-50" |
| 44 | + elif result=$(echo "$MODEL_CONFIG_PARAMS" | grep -oP 'model=str:\K[^ ]+'); then |
| 45 | + echo "Extracted MODEL from MODEL_CONFIG_PARAMS: $result" |
| 46 | + MODEL="$result" |
| 47 | + else |
| 48 | + echo "Warning: MODEL_CONFIG_PARAMS environment variable is set but model param is malformed. Your config will be discarded. Default values will be used." |
| 49 | + echo "MODEL_CONFIG_PARAMS should contain model in format -p model=str:your_model_name" |
| 50 | + echo "Following params will be used for cvat-cli: -p task=str:object-detection -p model=str:facebook/detr-resnet-50" |
| 51 | + MODEL_CONFIG_PARAMS="-p task=str:object-detection -p model=str:facebook/detr-resnet-50" |
| 52 | + MODEL="facebook/detr-resnet-50" |
| 53 | + fi |
| 54 | +} |
| 55 | + |
| 56 | +resolve_function_name() { |
| 57 | + if [ -z "$FUNCTION_NAME" ]; then |
| 58 | + echo "Warning: FUNCTION_NAME environment variable not found. Default is TRANSFORMERS" |
| 59 | + FUNCTION_NAME="TRANSFORMERS" |
| 60 | + else |
| 61 | + echo "Using FUNCTION_NAME: $FUNCTION_NAME" |
| 62 | + fi |
| 63 | +} |
| 64 | + |
| 65 | +common_env() { |
| 66 | + validate_access_token |
| 67 | + resolve_base_url |
| 68 | + resolve_org_slug |
| 69 | +} |
0 commit comments