Spaces:
Sleeping
Sleeping
Entrypoint to load model
Browse files- .DS_Store +0 -0
- .env +1 -1
- app/utils/download_model.py +24 -0
- entrypoint.sh +26 -0
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
.env
CHANGED
@@ -1 +1 @@
|
|
1 |
-
EC_ADMIN_PWD='$2b$12$zybxm7XMoGCVV3ovNDcXt.r2QJUhtj7miYfEfuBw9UGqViTIRFg72'
|
|
|
1 |
+
EC_ADMIN_PWD='$2b$12$zybxm7XMoGCVV3ovNDcXt.r2QJUhtj7miYfEfuBw9UGqViTIRFg72'
|
app/utils/download_model.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# /home/user/app/utils/download_model.py
|
2 |
+
import os
|
3 |
+
from transformers import AutoModel
|
4 |
+
|
5 |
+
def download_model():
|
6 |
+
# Use environment variables for the model name and directory
|
7 |
+
model_name = os.getenv("HF_MODEL_NAME")
|
8 |
+
model_dir = f"/home/user/data/models/{model_name}"
|
9 |
+
|
10 |
+
# Authenticate with Hugging Face using the token, if available
|
11 |
+
hf_token = os.getenv("HF_TOKEN")
|
12 |
+
if hf_token:
|
13 |
+
from huggingface_hub import HfFolder
|
14 |
+
HfFolder.save_token(hf_token) # Save the token for later use by the library
|
15 |
+
|
16 |
+
# Download the model
|
17 |
+
print(f"Downloading model: {model_name}...")
|
18 |
+
model = AutoModel.from_pretrained(model_name)
|
19 |
+
model.save_pretrained(model_dir)
|
20 |
+
print(f"Model {model_name} downloaded and saved to {model_dir}")
|
21 |
+
|
22 |
+
if __name__ == "__main__":
|
23 |
+
download_model()
|
24 |
+
|
entrypoint.sh
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# Authenticate with Hugging Face
|
4 |
+
export HF_HOME=/home/user/data/hf_cache
|
5 |
+
|
6 |
+
echo "Using Hugging Face API token for authentication"
|
7 |
+
export HF_TOKEN=${HF_TOKEN}
|
8 |
+
|
9 |
+
# Use the environment variable for the model name
|
10 |
+
MODEL_DIR="/home/user/data/models/${HF_MODEL_NAME}"
|
11 |
+
MODEL_URL=${HF_MODEL_URL} # Ensure consistent variable naming
|
12 |
+
|
13 |
+
# Download the model if it does not exist
|
14 |
+
if [ ! -d "$MODEL_DIR" ]; then
|
15 |
+
echo "Model not found. Downloading ${HF_MODEL_NAME} from ${MODEL_URL}..."
|
16 |
+
mkdir -p "$MODEL_DIR" # Ensure the directory exists before downloading
|
17 |
+
wget "$MODEL_URL" -P "$MODEL_DIR" || {
|
18 |
+
echo "Failed to download model from ${MODEL_URL}"
|
19 |
+
exit 1 # Exit if download fails
|
20 |
+
}
|
21 |
+
else
|
22 |
+
echo "Model ${HF_MODEL_NAME} already present."
|
23 |
+
fi
|
24 |
+
|
25 |
+
# Execute the main command of the container
|
26 |
+
exec "$@"
|