Spaces:
Running on Zero
Running on Zero
modularize weight download
Browse filesFiles changed (3)
- app.py+14-39
- utils/__init__.pyAdded+3
- utils/download_weights.pyAdded+30
7 unmodified lines891011121314151617181920212223242526272829303132333435369 unmodified lines46474849505152535455565758596061626364656667686970717 unmodified linesfrom atomworks.io.utils.visualize import viewfrom lightning.fabric import seed_everythingfrom rfd3.engine import RFD3InferenceConfig, RFD3InferenceEngine# Download model weights (skips already-downloaded models automatically)# In total, ~6GB (3GB for RFD3, 3GB for RF3, <100MB for MPNN); may take a few minutes depending on your connection speedcmd = f"foundry install rfd3 ligandmpnn rf3"print("Global PATH:", os.environ.get("PATH"))result = subprocess.run(cmd, shell=True, capture_output=True, text=True)if result.returncode == 0:print("Models installed successfully.")else:print(f"Error installing models: {result.stderr}")print(result.stdout)print(result.returncode)#download_dir = "./models/"#if not os.path.exists(download_dir):# cmd = "foundry install rfd3 ligandmpnn rf3"# result = subprocess.run(cmd, shell=True, capture_output=True, text=True)### Run once on startup: Install models if missing#checkpoint_dir = Path.home() / ".foundry" / "checkpoints"#os.environ["FOUNDRY_CHECKPOINT_DIRS"] = str(checkpoint_dir)#9 unmodified lines##install_models() # Executes on app.py load@spaces.GPU(duration=300)def test_rfd3():"""Run a quick rfd3 test design (minimal monomer, 1 step)."""try:cmd = ["rfd3","design","--seed", "42","contigmap.contigs=[A10]", # Tiny 10-res monomer"--num_designs", "1","inference.output_prefix=test_output","--inference.num_diffusion_steps", "10" # Fast test]result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)if result.returncode == 0:return "RFD3 test passed! Check test_output.pdb. Logs:\n" + result.stdout[-500:]else:return f"RFD3 test failed: {result.stderr}"except Exception as e:return f"Error: {str(e)}"@spaces.GPU(duration=300)def test_rfd3_from_notebook():7 unmodified lines89101112131415161718192021222324252627282930319 unmodified lines4142434445467 unmodified linesfrom atomworks.io.utils.visualize import viewfrom lightning.fabric import seed_everythingfrom rfd3.engine import RFD3InferenceConfig, RFD3InferenceEnginefrom utils import download_weights# foundry is a package installed automatically upon Space initialization through the Gradio SDK because it is listed in requirements.txt.# model weights are however not included in the package and must be downloaded separately.# the command "foundry install ..." automatically avoids re-downloading models if they are already present in the cache directory.#cmd = f"foundry install rfd3 ligandmpnn rf3"#result = subprocess.run(cmd, shell=True, capture_output=True, text=True)#if result.returncode == 0:# print("Models installed successfully.")#else:# print(f"Error installing models: {result.stderr}")# print(result.stdout)# print(result.returncode)download_weights()# Run once on startup: Install models if missing#checkpoint_dir = Path.home() / ".foundry" / "checkpoints"#os.environ["FOUNDRY_CHECKPOINT_DIRS"] = str(checkpoint_dir)#9 unmodified lines##install_models() # Executes on app.py load@spaces.GPU(duration=300)def test_rfd3_from_notebook():
123from utils.download_weights import *
__all__ = ["download_weights"]123456789101112131415161718192021222324252627282930import subprocessimport osfrom pathlib import Path
MODELS = ["rfd3", "ligandmpnn", "rf3"]
# foundry is a package installed automatically upon Space initialization through the Gradio SDK because it is listed in requirements.txt. # model weights are however not included in the package and must be downloaded separately.# the command "foundry install ..." automatically avoids re-downloading models if they are already present in the cache directory.# we however manually check for debugging purposes.
def download_weights(): """Download model weights using foundry CLI, skipping already-downloaded models."""
checkpoint_dir = Path.home() / ".foundry" / "checkpoints" for model in MODELS: model_path = os.path.join(checkpoint_dir, model+".ckpt") if model_path.exists(): print(f"{model} already exists at {model_path}, skipping download.") else: cmd = f"foundry install {model} --checkpoint-dir {checkpoint_dir}" print(f"Installing {model}...") result = subprocess.run(cmd, shell=True, capture_output=True, text=True) if result.returncode == 0: print(f"{model} installed successfully.") else: print(f"Error installing {model}: {result.stderr}") print(result.stdout) print(result.returncode)app.py+14-39
utils/__init__.pyAdded+3
utils/download_weights.pyAdded+30