Spaces:
Running
on
Zero
Running
on
Zero
build: unzip knapsack_cache.zip if it exists
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ import logging
|
|
10 |
from pathlib import Path
|
11 |
from omegaconf import OmegaConf, DictConfig
|
12 |
from gradio_log import Log
|
|
|
13 |
|
14 |
# --- InstaNovo Imports ---
|
15 |
try:
|
@@ -127,6 +128,18 @@ def load_models_and_knapsack():
|
|
127 |
# --- Knapsack Handling ---
|
128 |
# Only attempt knapsack loading/generation if the Transformer model is loaded
|
129 |
if INSTANOVO is not None and RESIDUE_SET is not None and KNAPSACK is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
knapsack_exists = (
|
131 |
(KNAPSACK_DIR / "parameters.pkl").exists()
|
132 |
and (KNAPSACK_DIR / "masses.npy").exists()
|
|
|
10 |
from pathlib import Path
|
11 |
from omegaconf import OmegaConf, DictConfig
|
12 |
from gradio_log import Log
|
13 |
+
import zipfile
|
14 |
|
15 |
# --- InstaNovo Imports ---
|
16 |
try:
|
|
|
128 |
# --- Knapsack Handling ---
|
129 |
# Only attempt knapsack loading/generation if the Transformer model is loaded
|
130 |
if INSTANOVO is not None and RESIDUE_SET is not None and KNAPSACK is None:
|
131 |
+
# Check if knapsack_cache.zip exists and unzip its contents
|
132 |
+
knapsack_zip_path = Path("knapsack_cache.zip")
|
133 |
+
if knapsack_zip_path.exists():
|
134 |
+
logger.info(f"Found {knapsack_zip_path}. Extracting contents to {KNAPSACK_DIR}...")
|
135 |
+
try:
|
136 |
+
with zipfile.ZipFile(knapsack_zip_path, 'r') as zip_ref:
|
137 |
+
zip_ref.extractall(KNAPSACK_DIR)
|
138 |
+
logger.info("Knapsack cache extracted successfully.")
|
139 |
+
except Exception as e:
|
140 |
+
logger.error(f"Failed to extract {knapsack_zip_path}: {e}")
|
141 |
+
raise gr.Error(f"Failed to extract knapsack cache: {e}")
|
142 |
+
|
143 |
knapsack_exists = (
|
144 |
(KNAPSACK_DIR / "parameters.pkl").exists()
|
145 |
and (KNAPSACK_DIR / "masses.npy").exists()
|