Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -99,7 +99,7 @@ def predictmic(sequence):
|
|
99 |
import torch
|
100 |
from transformers import BertTokenizer, BertModel
|
101 |
import numpy as np
|
102 |
-
import pickle
|
103 |
from math import expm1
|
104 |
|
105 |
# === Load ProtBert model ===
|
@@ -142,7 +142,7 @@ def predictmic(sequence):
|
|
142 |
"K.Pneumonia": {
|
143 |
"model": "pne_mlp_model.pkl",
|
144 |
"scaler": "pne_scaler.pkl",
|
145 |
-
"pca": "pne_pca"
|
146 |
}
|
147 |
}
|
148 |
|
@@ -151,21 +151,18 @@ def predictmic(sequence):
|
|
151 |
for bacterium, cfg in bacteria_config.items():
|
152 |
try:
|
153 |
# === Load scaler and transform ===
|
154 |
-
|
155 |
-
scaler = pickle.load(f)
|
156 |
scaled = scaler.transform(embedding)
|
157 |
|
158 |
# === Apply PCA if exists ===
|
159 |
if cfg["pca"] is not None:
|
160 |
-
|
161 |
-
pca = pickle.load(f)
|
162 |
transformed = pca.transform(scaled)
|
163 |
else:
|
164 |
transformed = scaled
|
165 |
|
166 |
# === Load model and predict ===
|
167 |
-
|
168 |
-
mic_model = pickle.load(f)
|
169 |
mic_log = mic_model.predict(transformed)[0]
|
170 |
mic = round(expm1(mic_log), 3) # Inverse of log1p used in training
|
171 |
|
|
|
99 |
import torch
|
100 |
from transformers import BertTokenizer, BertModel
|
101 |
import numpy as np
|
102 |
+
import joblib # ✅ Use joblib instead of pickle
|
103 |
from math import expm1
|
104 |
|
105 |
# === Load ProtBert model ===
|
|
|
142 |
"K.Pneumonia": {
|
143 |
"model": "pne_mlp_model.pkl",
|
144 |
"scaler": "pne_scaler.pkl",
|
145 |
+
"pca": "pne_pca" # Ensure this PCA file was also saved using joblib
|
146 |
}
|
147 |
}
|
148 |
|
|
|
151 |
for bacterium, cfg in bacteria_config.items():
|
152 |
try:
|
153 |
# === Load scaler and transform ===
|
154 |
+
scaler = joblib.load(cfg["scaler"])
|
|
|
155 |
scaled = scaler.transform(embedding)
|
156 |
|
157 |
# === Apply PCA if exists ===
|
158 |
if cfg["pca"] is not None:
|
159 |
+
pca = joblib.load(cfg["pca"])
|
|
|
160 |
transformed = pca.transform(scaled)
|
161 |
else:
|
162 |
transformed = scaled
|
163 |
|
164 |
# === Load model and predict ===
|
165 |
+
mic_model = joblib.load(cfg["model"])
|
|
|
166 |
mic_log = mic_model.predict(transformed)[0]
|
167 |
mic = round(expm1(mic_log), 3) # Inverse of log1p used in training
|
168 |
|