harp-dev commited on
Commit
384f954
·
verified ·
1 Parent(s): 977d5f4

Fetch every instrument when the image is built

Browse files

Each instrument was downloaded from the Magenta bucket on Google Cloud Storage the first time a request picked it. The image now holds all five.

Files changed (2) hide show
  1. Dockerfile +7 -0
  2. backend_worker.py +3 -1
Dockerfile CHANGED
@@ -48,5 +48,12 @@ RUN /usr/local/bin/python3.10 -m venv "$FRONTEND_VENV" \
48
  COPY backend_worker.py frontend_app.py start.sh ./
49
  RUN chmod +x /app/start.sh
50
 
 
 
 
 
 
 
 
51
  EXPOSE 7860
52
  CMD ["/app/start.sh"]
 
48
  COPY backend_worker.py frontend_app.py start.sh ./
49
  RUN chmod +x /app/start.sh
50
 
51
+ # Every instrument's checkpoint, from the Magenta bucket the backend would otherwise reach on the
52
+ # first request for each instrument. Set here, after the environments, so that their layers stay
53
+ # cached.
54
+ ENV DDSP_MODELS_DIR=/opt/ddsp_pretrained
55
+ RUN "$BACKEND_PYTHON" -c "import backend_worker as w; [w._ensure_model(m) for m in w.PRETRAINED_MODELS]" \
56
+ && chmod -R a+rX "$DDSP_MODELS_DIR"
57
+
58
  EXPOSE 7860
59
  CMD ["/app/start.sh"]
backend_worker.py CHANGED
@@ -39,7 +39,9 @@ SAMPLE_RATE = 16000
39
  PRETRAINED_MODELS = ["Violin", "Flute", "Flute2", "Trumpet", "Tenor_Saxophone"]
40
  _GCS_BUCKET = "ddsp"
41
  _GCS_PREFIX = "models/timbre_transfer_colab/2021-07-08"
42
- _MODELS_DIR = "/tmp/ddsp_pretrained"
 
 
43
  os.makedirs(_MODELS_DIR, exist_ok=True)
44
 
45
 
 
39
  PRETRAINED_MODELS = ["Violin", "Flute", "Flute2", "Trumpet", "Tenor_Saxophone"]
40
  _GCS_BUCKET = "ddsp"
41
  _GCS_PREFIX = "models/timbre_transfer_colab/2021-07-08"
42
+ # The image fetches every instrument when it is built (see the Dockerfile), so no request waits on
43
+ # Google Cloud Storage. A directory without one still downloads it on first use.
44
+ _MODELS_DIR = os.environ.get("DDSP_MODELS_DIR", "/tmp/ddsp_pretrained")
45
  os.makedirs(_MODELS_DIR, exist_ok=True)
46
 
47