Geonomic commited on
Commit
3cb27a5
·
verified ·
1 Parent(s): 27eb7c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -9,38 +9,37 @@ import torch.nn.functional as F
9
  from Bio.Blast import NCBIWWW, NCBIXML
10
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoModel
11
  from huggingface_hub import hf_hub_download
12
- import spaces # REQUIRED FOR ZEROGPU
13
 
14
  # ===================================
15
  # 1. LOAD AI MODELS (GLOBALLY CACHED)
16
  # ===================================
17
  print("Waking up the Genomic Oracle...\n")
18
 
19
- # A. Kadir's Gatekeeper (Local in the Space)
20
  print("Loading Logression Model...\n")
21
  clf_coding = joblib.load("coding_classifier_universal.joblib")
22
 
23
- # B. Base DNABERT (Local in the Space)
24
- print("Loading foundational DNABERT Model Architecture...\n")
25
  tokenizer_base = AutoTokenizer.from_pretrained("DNABERT_Local", trust_remote_code=True)
26
- model_base = AutoModel.from_pretrained("DNABERT_Local", trust_remote_code=True, low_cpu_mem_usage=False)
27
  model_base.eval()
28
 
29
- # C. DNABERT-2 Promoter Model (Local in the Space)
30
  print("Loading DNABERT-2 Neural Network...\n")
31
  tokenizer_promoter = AutoTokenizer.from_pretrained("llm_promoter_classifier_v2", trust_remote_code=True)
32
- model_promoter = AutoModelForSequenceClassification.from_pretrained("llm_promoter_classifier_v2", trust_remote_code=True, low_cpu_mem_usage=False)
33
  model_promoter.eval()
34
 
35
- # D. Multi-Feature LightGBM (Fetched from Cloud Repo)
36
  print("Downloading LightGBM from Model Repository...")
37
  lgbm_path = hf_hub_download(repo_id="Geonomic/Genomic-Oracle-Weights", filename="dnabert_lightgbm_model_feature_type.pkl")
38
  lightgbm_model = joblib.load(lgbm_path)
39
 
40
- # E. Custom ALiBi Lean/Obese BERT (Fetched from Cloud Repo)
41
  print("Downloading Phenotype BERT from Model Repository...")
42
  tokenizer_pheno = AutoTokenizer.from_pretrained("Geonomic/Genomic-Oracle-Weights", trust_remote_code=True)
43
- model_pheno = AutoModelForSequenceClassification.from_pretrained("Geonomic/Genomic-Oracle-Weights", trust_remote_code=True, low_cpu_mem_usage=False)
44
  model_pheno.eval()
45
 
46
  # Structural Feature Dictionary
@@ -52,7 +51,9 @@ FEATURE_DICT = {
52
  # ==============================================
53
  # 2. CORE INFERENCE ENGINE (ZeroGPU Accelerated)
54
  # ==============================================
55
- @spaces.GPU # This tells Hugging Face to teleport this specific math to the A100 GPU
 
 
56
  def run_deep_learning_cascade(dna_sequence):
57
  device = torch.device("cuda") # Wakes up the A100 connection
58
  clean_seq = "".join(dna_sequence.split()).upper()
 
9
  from Bio.Blast import NCBIWWW, NCBIXML
10
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoModel
11
  from huggingface_hub import hf_hub_download
 
12
 
13
  # ===================================
14
  # 1. LOAD AI MODELS (GLOBALLY CACHED)
15
  # ===================================
16
  print("Waking up the Genomic Oracle...\n")
17
 
18
+ # A. Kadir's Gatekeeper
19
  print("Loading Logression Model...\n")
20
  clf_coding = joblib.load("coding_classifier_universal.joblib")
21
 
22
+ # B. Base DNABERT
23
+ print("Loading foundational DNABERT Architecture...\n")
24
  tokenizer_base = AutoTokenizer.from_pretrained("DNABERT_Local", trust_remote_code=True)
25
+ model_base = AutoModel.from_pretrained("DNABERT_Local", trust_remote_code=True)
26
  model_base.eval()
27
 
28
+ # C. DNABERT-2 Promoter Model
29
  print("Loading DNABERT-2 Neural Network...\n")
30
  tokenizer_promoter = AutoTokenizer.from_pretrained("llm_promoter_classifier_v2", trust_remote_code=True)
31
+ model_promoter = AutoModelForSequenceClassification.from_pretrained("llm_promoter_classifier_v2", trust_remote_code=True)
32
  model_promoter.eval()
33
 
34
+ # D. Multi-Feature LightGBM
35
  print("Downloading LightGBM from Model Repository...")
36
  lgbm_path = hf_hub_download(repo_id="Geonomic/Genomic-Oracle-Weights", filename="dnabert_lightgbm_model_feature_type.pkl")
37
  lightgbm_model = joblib.load(lgbm_path)
38
 
39
+ # E. Custom ALiBi Lean/Obese BERT
40
  print("Downloading Phenotype BERT from Model Repository...")
41
  tokenizer_pheno = AutoTokenizer.from_pretrained("Geonomic/Genomic-Oracle-Weights", trust_remote_code=True)
42
+ model_pheno = AutoModelForSequenceClassification.from_pretrained("Geonomic/Genomic-Oracle-Weights", trust_remote_code=True)
43
  model_pheno.eval()
44
 
45
  # Structural Feature Dictionary
 
51
  # ==============================================
52
  # 2. CORE INFERENCE ENGINE (ZeroGPU Accelerated)
53
  # ==============================================
54
+ import spaces # Import ZeroGPU here to prevent the PyTorch Meta Device Error
55
+
56
+ @spaces.GPU
57
  def run_deep_learning_cascade(dna_sequence):
58
  device = torch.device("cuda") # Wakes up the A100 connection
59
  clean_seq = "".join(dna_sequence.split()).upper()