Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,14 +19,10 @@ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
|
| 19 |
RNG_SEED = int(os.getenv("RNG_SEED", "42"))
|
| 20 |
|
| 21 |
# WT definition (used for parity ELBO computation)
|
| 22 |
-
WT_ID = "OR293627.1|translated"
|
| 23 |
WT_SEQUENCE = (
|
| 24 |
"MLGKCLTAGYCSQLLFFWCIVPFCFAALVNAASNSSSHLQLIYNLTICELNGTDWLNQKFDWAVETFVIFPVLTHIVSYGALTTSHFLDTAGLITVSTAGYYHGRYVLSSIYAVFALAALICFVIRLTKNCMSWRYSCTRYTNFLLDTKGNLYRWRSPVVIERRGKVEVGDHLIDLKRVVLDGSAATPITKISAEQWGRP"
|
| 25 |
)
|
| 26 |
|
| 27 |
-
# Fitness rescale
|
| 28 |
-
MIN_F, MAX_F = -6200.0, 6200.0
|
| 29 |
-
|
| 30 |
# Valid symbols for ESM
|
| 31 |
VALID = set("ACDEFGHIKLMNPQRSTVWYBXZ")
|
| 32 |
|
|
@@ -81,12 +77,12 @@ def elbo_batch_from_embeddings(model: VAE_model, emb_batch: torch.Tensor, determ
|
|
| 81 |
ELBO_b, BCE_b, KLD_b = model.all_likelihood_components(emb_batch, deterministic=True)
|
| 82 |
return ELBO_b.detach().cpu().numpy()
|
| 83 |
except TypeError:
|
| 84 |
-
# Fallback: use a reseeded single-sample ELBO
|
| 85 |
_set_seeds(RNG_SEED)
|
| 86 |
ELBO_b, BCE_b, KLD_b = model.all_likelihood_components(emb_batch)
|
| 87 |
return ELBO_b.detach().cpu().numpy()
|
| 88 |
else:
|
| 89 |
-
# Explicitly stochastic mode
|
| 90 |
ELBO_b, BCE_b, KLD_b = model.all_likelihood_components(emb_batch)
|
| 91 |
return ELBO_b.detach().cpu().numpy()
|
| 92 |
|
|
@@ -221,8 +217,7 @@ def _ensure_ready():
|
|
| 221 |
|
| 222 |
def score(sequence: str) -> str:
|
| 223 |
"""
|
| 224 |
-
|
| 225 |
-
- Try to use the model's deterministic path (posterior mean z=mu).
|
| 226 |
- If not supported, fall back to reseeding before each ELBO call
|
| 227 |
so identical inputs produce identical ELBOs.
|
| 228 |
"""
|
|
@@ -258,7 +253,7 @@ def score(sequence: str) -> str:
|
|
| 258 |
f"WT ELBO: {wt_elbo:.4f}\n"
|
| 259 |
f"Seq ELBO: {test_elbo:.4f}\n"
|
| 260 |
f"Evol. index (Seq - WT): {evol_index:.4f}\n"
|
| 261 |
-
f"Fitness
|
| 262 |
)
|
| 263 |
|
| 264 |
# ---------------------------
|
|
@@ -273,7 +268,7 @@ demo = gr.Interface(
|
|
| 273 |
placeholder="Sequence must be exactly 200 aa long"
|
| 274 |
),
|
| 275 |
outputs=gr.Textbox(label="Result"),
|
| 276 |
-
title="Fitness scorer (ESM2 + VAE on embeddings)",
|
| 277 |
)
|
| 278 |
|
| 279 |
if __name__ == "__main__":
|
|
|
|
| 19 |
RNG_SEED = int(os.getenv("RNG_SEED", "42"))
|
| 20 |
|
| 21 |
# WT definition (used for parity ELBO computation)
|
|
|
|
| 22 |
WT_SEQUENCE = (
|
| 23 |
"MLGKCLTAGYCSQLLFFWCIVPFCFAALVNAASNSSSHLQLIYNLTICELNGTDWLNQKFDWAVETFVIFPVLTHIVSYGALTTSHFLDTAGLITVSTAGYYHGRYVLSSIYAVFALAALICFVIRLTKNCMSWRYSCTRYTNFLLDTKGNLYRWRSPVVIERRGKVEVGDHLIDLKRVVLDGSAATPITKISAEQWGRP"
|
| 24 |
)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
| 26 |
# Valid symbols for ESM
|
| 27 |
VALID = set("ACDEFGHIKLMNPQRSTVWYBXZ")
|
| 28 |
|
|
|
|
| 77 |
ELBO_b, BCE_b, KLD_b = model.all_likelihood_components(emb_batch, deterministic=True)
|
| 78 |
return ELBO_b.detach().cpu().numpy()
|
| 79 |
except TypeError:
|
| 80 |
+
# Fallback: use a reseeded single-sample ELBO
|
| 81 |
_set_seeds(RNG_SEED)
|
| 82 |
ELBO_b, BCE_b, KLD_b = model.all_likelihood_components(emb_batch)
|
| 83 |
return ELBO_b.detach().cpu().numpy()
|
| 84 |
else:
|
| 85 |
+
# Explicitly stochastic mode
|
| 86 |
ELBO_b, BCE_b, KLD_b = model.all_likelihood_components(emb_batch)
|
| 87 |
return ELBO_b.detach().cpu().numpy()
|
| 88 |
|
|
|
|
| 217 |
|
| 218 |
def score(sequence: str) -> str:
|
| 219 |
"""
|
| 220 |
+
Try to use the model's deterministic path (posterior mean z=mu).
|
|
|
|
| 221 |
- If not supported, fall back to reseeding before each ELBO call
|
| 222 |
so identical inputs produce identical ELBOs.
|
| 223 |
"""
|
|
|
|
| 253 |
f"WT ELBO: {wt_elbo:.4f}\n"
|
| 254 |
f"Seq ELBO: {test_elbo:.4f}\n"
|
| 255 |
f"Evol. index (Seq - WT): {evol_index:.4f}\n"
|
| 256 |
+
f"Fitness: {fitness:.2f}"
|
| 257 |
)
|
| 258 |
|
| 259 |
# ---------------------------
|
|
|
|
| 268 |
placeholder="Sequence must be exactly 200 aa long"
|
| 269 |
),
|
| 270 |
outputs=gr.Textbox(label="Result"),
|
| 271 |
+
title="EscaPRRS Fitness scorer (ESM2 + VAE on embeddings)",
|
| 272 |
)
|
| 273 |
|
| 274 |
if __name__ == "__main__":
|