Geonomic commited on
Commit
95a047f
·
verified ·
1 Parent(s): 3cb27a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -33
app.py CHANGED
@@ -9,38 +9,12 @@ 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
 
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
46
  FEATURE_DICT = {
@@ -51,17 +25,35 @@ FEATURE_DICT = {
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()
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  # --- LEVEL 1: Base Embedding & Kadir's Gatekeeper ---
62
  inputs = tokenizer_base([clean_seq], return_tensors="pt", max_length=300, truncation=True, padding=True)
63
  inputs = {k: v.to(device) for k, v in inputs.items()}
64
-
65
  with torch.no_grad():
66
  out_base = model_base(**inputs)
67
  mask = inputs["attention_mask"].unsqueeze(-1)
 
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. GLOBAL VARIABLES
16
  # ===================================
17
+ print("Waking up the Genomic Oracle... Awaiting sequence for Immediate GPU Access.\n")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  # Structural Feature Dictionary
20
  FEATURE_DICT = {
 
25
  # ==============================================
26
  # 2. CORE INFERENCE ENGINE (ZeroGPU Accelerated)
27
  # ==============================================
28
+ @spaces.GPU # This tells Hugging Face to teleport this specific math to the A100 GPU
 
 
29
  def run_deep_learning_cascade(dna_sequence):
30
  device = torch.device("cuda") # Wakes up the A100 connection
31
  clean_seq = "".join(dna_sequence.split()).upper()
32
 
33
+ print("🚀 Allocated GPU is Awake! Loading ALiBi models directly into VRAM...")
34
+
35
+ # --- JUST-IN-TIME MODEL LOADING ---
36
+ clf_coding = joblib.load("coding_classifier_universal.joblib")
37
+
38
+ tokenizer_base = AutoTokenizer.from_pretrained("DNABERT_Local", trust_remote_code=True)
39
+ model_base = AutoModel.from_pretrained("DNABERT_Local", trust_remote_code=True).to(device)
40
+ model_base.eval()
41
+
42
+ tokenizer_promoter = AutoTokenizer.from_pretrained("llm_promoter_classifier_v2", trust_remote_code=True)
43
+ model_promoter = AutoModelForSequenceClassification.from_pretrained("llm_promoter_classifier_v2", trust_remote_code=True).to(device)
44
+ model_promoter.eval()
45
+
46
+ lgbm_path = hf_hub_download(repo_id="Geonomic/Genomic-Oracle-Weights", filename="dnabert_lightgbm_model_feature_type.pkl")
47
+ lightgbm_model = joblib.load(lgbm_path)
48
+
49
+ tokenizer_pheno = AutoTokenizer.from_pretrained("Geonomic/Genomic-Oracle-Weights", trust_remote_code=True)
50
+ model_pheno = AutoModelForSequenceClassification.from_pretrained("Geonomic/Genomic-Oracle-Weights", trust_remote_code=True).to(device)
51
+ model_pheno.eval()
52
+
53
  # --- LEVEL 1: Base Embedding & Kadir's Gatekeeper ---
54
  inputs = tokenizer_base([clean_seq], return_tensors="pt", max_length=300, truncation=True, padding=True)
55
  inputs = {k: v.to(device) for k, v in inputs.items()}
56
+
57
  with torch.no_grad():
58
  out_base = model_base(**inputs)
59
  mask = inputs["attention_mask"].unsqueeze(-1)