|
7 | 7 | PORT = 8080 |
8 | 8 |
|
9 | 9 | REPO_ROOT = Path(__file__).parent.parent.parent |
10 | | -EXPERIMENTS_ZIP = os.environ.get("ALIGN_EXPERIMENTS_ZIP") |
| 10 | +EXPERIMENTS = os.environ.get("EXPERIMENTS") |
| 11 | +EXPERIMENTS_PATH = Path(EXPERIMENTS) if EXPERIMENTS else None |
11 | 12 |
|
12 | 13 | app = modal.App("align-app") |
13 | 14 |
|
@@ -36,25 +37,30 @@ def download_models(): |
36 | 37 | .workdir("/app") |
37 | 38 | ) |
38 | 39 |
|
39 | | -if EXPERIMENTS_ZIP: |
40 | | - image = ( |
41 | | - base_image.add_local_file(EXPERIMENTS_ZIP, "/app/experiments.zip", copy=True) |
42 | | - .run_commands( |
43 | | - "poetry config virtualenvs.create false && poetry install --only main", |
44 | | - "unzip experiments.zip -d /app && rm experiments.zip", |
| 40 | +image = base_image |
| 41 | + |
| 42 | +if EXPERIMENTS_PATH and EXPERIMENTS_PATH.exists(): |
| 43 | + if EXPERIMENTS_PATH.is_dir(): |
| 44 | + image = image.add_local_dir( |
| 45 | + str(EXPERIMENTS_PATH), "/app/experiments", copy=True |
45 | 46 | ) |
46 | | - .run_function( |
47 | | - download_models, |
48 | | - secrets=[modal.Secret.from_name("huggingface")], |
| 47 | + elif EXPERIMENTS_PATH.suffix.lower() == ".zip": |
| 48 | + image = image.add_local_file( |
| 49 | + str(EXPERIMENTS_PATH), "/app/experiments.zip", copy=True |
49 | 50 | ) |
50 | | - ) |
51 | | -else: |
52 | | - image = base_image.run_commands( |
53 | | - "poetry config virtualenvs.create false && poetry install --only main" |
54 | | - ).run_function( |
55 | | - download_models, |
56 | | - secrets=[modal.Secret.from_name("huggingface")], |
57 | | - ) |
| 51 | + |
| 52 | +install_commands = [ |
| 53 | + "poetry config virtualenvs.create false && poetry install --only main", |
| 54 | +] |
| 55 | + |
| 56 | +if EXPERIMENTS_PATH and EXPERIMENTS_PATH.exists(): |
| 57 | + if EXPERIMENTS_PATH.is_file() and EXPERIMENTS_PATH.suffix.lower() == ".zip": |
| 58 | + install_commands.append("unzip experiments.zip -d /app && rm experiments.zip") |
| 59 | + |
| 60 | +image = image.run_commands(*install_commands).run_function( |
| 61 | + download_models, |
| 62 | + secrets=[modal.Secret.from_name("huggingface")], |
| 63 | +) |
58 | 64 |
|
59 | 65 |
|
60 | 66 | @app.function( |
|
0 commit comments