dtyago commited on
Commit
5659717
1 Parent(s): 10399f1

Fixed export of MODEL_PATH

Browse files
Files changed (2) hide show
  1. app/utils/download_model.py +7 -4
  2. entrypoint.sh +3 -1
app/utils/download_model.py CHANGED
@@ -2,6 +2,9 @@ import os
2
  import requests
3
  from transformers import AutoModel
4
 
 
 
 
5
  def model_file_exists_and_valid(model_file_path):
6
  # Check if the model file exists and has a size greater than 0
7
  return os.path.exists(model_file_path) and os.path.getsize(model_file_path) > 0
@@ -17,7 +20,7 @@ def download_hf_model():
17
 
18
  if model_file_exists_and_valid(model_file_path):
19
  print(f"Model {model_name} already downloaded.")
20
- os.environ['MODEL_PATH'] = model_file_path
21
  return
22
 
23
  # Authenticate with Hugging Face using the token, if available
@@ -30,7 +33,7 @@ def download_hf_model():
30
  model = AutoModel.from_pretrained(model_name)
31
  model.save_pretrained(model_dir)
32
  print(f"Model {model_name} downloaded and saved to {model_dir}")
33
- os.environ['MODEL_PATH'] = model_file_path
34
 
35
  def download_gguf_model():
36
  model_name = os.getenv("HF_MODEL_NAME")
@@ -42,7 +45,7 @@ def download_gguf_model():
42
 
43
  if model_file_exists_and_valid(model_file_path):
44
  print(f"Model {model_name} already downloaded.")
45
- os.environ['MODEL_PATH'] = model_file_path
46
  return
47
 
48
  print(f"Downloading model from {model_url}...")
@@ -53,7 +56,7 @@ def download_gguf_model():
53
  print(f"Model downloaded and saved to {model_file_path}")
54
  else:
55
  print(f"Failed to download the model. Status code: {response.status_code}")
56
- os.environ['MODEL_PATH'] = model_file_path
57
 
58
  def download_model():
59
  model_class = os.getenv("MODEL_CLASS")
 
2
  import requests
3
  from transformers import AutoModel
4
 
5
+ '''
6
+ DO NOT PRINT ANYTHING OTHER THAN MODEL PATH IN THIS SCRIPT, THIS IS BEING EXPORTED BY DOCKER ENTRY POINT!
7
+ '''
8
  def model_file_exists_and_valid(model_file_path):
9
  # Check if the model file exists and has a size greater than 0
10
  return os.path.exists(model_file_path) and os.path.getsize(model_file_path) > 0
 
20
 
21
  if model_file_exists_and_valid(model_file_path):
22
  print(f"Model {model_name} already downloaded.")
23
+ print(model_file_path)
24
  return
25
 
26
  # Authenticate with Hugging Face using the token, if available
 
33
  model = AutoModel.from_pretrained(model_name)
34
  model.save_pretrained(model_dir)
35
  print(f"Model {model_name} downloaded and saved to {model_dir}")
36
+ print(model_file_path)
37
 
38
  def download_gguf_model():
39
  model_name = os.getenv("HF_MODEL_NAME")
 
45
 
46
  if model_file_exists_and_valid(model_file_path):
47
  print(f"Model {model_name} already downloaded.")
48
+ print(model_file_path)
49
  return
50
 
51
  print(f"Downloading model from {model_url}...")
 
56
  print(f"Model downloaded and saved to {model_file_path}")
57
  else:
58
  print(f"Failed to download the model. Status code: {response.status_code}")
59
+ print(model_file_path)
60
 
61
  def download_model():
62
  model_class = os.getenv("MODEL_CLASS")
entrypoint.sh CHANGED
@@ -18,7 +18,9 @@ if [ ! -d "$MODEL_DIR" ]; then
18
 
19
  # Execute the download_model script
20
  echo "Downloading the model..."
21
- python download_model.py || { echo "Model download failed"; exit 1; }
 
 
22
 
23
  # Navigate back to the app directory
24
  cd /home/user/app
 
18
 
19
  # Execute the download_model script
20
  echo "Downloading the model..."
21
+ MODEL_PATH=$(python download_model.py) || { echo "Model download failed"; exit 1; }
22
+ export MODEL_PATH
23
+
24
 
25
  # Navigate back to the app directory
26
  cd /home/user/app