fohy24 commited on
Commit
997386f
·
1 Parent(s): a960175

download GCS model to to cache

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -57,13 +57,18 @@ def predict(img, confidence):
57
  # Download model from GCS
58
  model_path = os.getenv('MODEL_PATH')
59
  response = requests.get(model_path)
60
- time.sleep(30)
61
 
62
- with open('model.pt', 'wb') as f:
 
 
 
 
 
 
63
  f.write(response.content)
64
- time.sleep(30)
65
 
66
- checkpoint = torch.load('model.pt', map_location=device)
67
  densenet.load_state_dict(checkpoint['model_state_dict'])
68
 
69
  densenet.eval()
 
57
  # Download model from GCS
58
  model_path = os.getenv('MODEL_PATH')
59
  response = requests.get(model_path)
60
+ time.sleep(20)
61
 
62
+ # Define the cache directory path
63
+ cache_dir = os.path.expanduser("~/.cache/torch/hub/checkpoints")
64
+ model_file_name = os.path.basename(model_path)
65
+ model_file_path = os.path.join(cache_dir, model_file_name)
66
+ print(model_file_path)
67
+
68
+ with open(model_file_path, 'wb') as f:
69
  f.write(response.content)
 
70
 
71
+ checkpoint = torch.load(model_file_path, map_location=device)
72
  densenet.load_state_dict(checkpoint['model_state_dict'])
73
 
74
  densenet.eval()