Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,10 +19,11 @@ MAFFT_PATH = "mafft/mafftdir/bin/mafft"
|
|
| 19 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 20 |
|
| 21 |
# --- Paths ---
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 26 |
csv_path = "f gene clean dataset.csv"
|
| 27 |
|
| 28 |
# --- Load Models ---
|
|
@@ -30,27 +31,31 @@ boundary_model = None
|
|
| 30 |
keras_model = None
|
| 31 |
kmer_to_index = None
|
| 32 |
|
| 33 |
-
# Try to load boundary model
|
| 34 |
try:
|
|
|
|
| 35 |
if os.path.exists(boundary_path):
|
| 36 |
boundary_model = GenePredictor(boundary_path)
|
| 37 |
-
logging.info("Boundary model loaded successfully.")
|
| 38 |
else:
|
| 39 |
-
logging.warning(f"Boundary model file not found
|
| 40 |
except Exception as e:
|
| 41 |
-
logging.error(f"Failed to load boundary model: {e}")
|
| 42 |
|
| 43 |
-
# Try to load Keras model
|
| 44 |
try:
|
|
|
|
|
|
|
|
|
|
| 45 |
if os.path.exists(keras_path) and os.path.exists(kmer_path):
|
| 46 |
keras_model = load_model(keras_path)
|
| 47 |
with open(kmer_path, "rb") as f:
|
| 48 |
kmer_to_index = pickle.load(f)
|
| 49 |
-
logging.info("Keras model and k-mer index loaded successfully.")
|
| 50 |
else:
|
| 51 |
-
logging.warning(f"Keras model or kmer files not found
|
| 52 |
except Exception as e:
|
| 53 |
-
logging.error(f"Failed to load Keras model: {e}")
|
| 54 |
|
| 55 |
# --- Keras Prediction ---
|
| 56 |
def predict_with_keras(sequence):
|
|
|
|
| 19 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 20 |
|
| 21 |
# --- Paths ---
|
| 22 |
+
from huggingface_hub import hf_hub_download
|
| 23 |
+
import tempfile
|
| 24 |
+
|
| 25 |
+
# Model repository and file paths
|
| 26 |
+
model_repo = "GGproject10/best_boundary_aware_model"
|
| 27 |
csv_path = "f gene clean dataset.csv"
|
| 28 |
|
| 29 |
# --- Load Models ---
|
|
|
|
| 31 |
keras_model = None
|
| 32 |
kmer_to_index = None
|
| 33 |
|
| 34 |
+
# Try to load boundary model from Hugging Face Hub
|
| 35 |
try:
|
| 36 |
+
boundary_path = hf_hub_download(repo_id=model_repo, filename="best_boundary_aware_model.pth")
|
| 37 |
if os.path.exists(boundary_path):
|
| 38 |
boundary_model = GenePredictor(boundary_path)
|
| 39 |
+
logging.info("Boundary model loaded successfully from Hugging Face Hub.")
|
| 40 |
else:
|
| 41 |
+
logging.warning(f"Boundary model file not found after download")
|
| 42 |
except Exception as e:
|
| 43 |
+
logging.error(f"Failed to load boundary model from HF Hub: {e}")
|
| 44 |
|
| 45 |
+
# Try to load Keras model from Hugging Face Hub
|
| 46 |
try:
|
| 47 |
+
keras_path = hf_hub_download(repo_id=model_repo, filename="best_model.keras")
|
| 48 |
+
kmer_path = hf_hub_download(repo_id=model_repo, filename="kmer_to_index.pkl")
|
| 49 |
+
|
| 50 |
if os.path.exists(keras_path) and os.path.exists(kmer_path):
|
| 51 |
keras_model = load_model(keras_path)
|
| 52 |
with open(kmer_path, "rb") as f:
|
| 53 |
kmer_to_index = pickle.load(f)
|
| 54 |
+
logging.info("Keras model and k-mer index loaded successfully from Hugging Face Hub.")
|
| 55 |
else:
|
| 56 |
+
logging.warning(f"Keras model or kmer files not found after download")
|
| 57 |
except Exception as e:
|
| 58 |
+
logging.error(f"Failed to load Keras model from HF Hub: {e}")
|
| 59 |
|
| 60 |
# --- Keras Prediction ---
|
| 61 |
def predict_with_keras(sequence):
|