Geonomic commited on
Commit
fdae30d
·
verified ·
1 Parent(s): dcfc166

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -25
app.py CHANGED
@@ -9,12 +9,34 @@ 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. 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,31 +47,13 @@ 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, low_cpu_mem_usage=False).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, low_cpu_mem_usage=False).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, low_cpu_mem_usage=False).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()}
@@ -203,7 +207,7 @@ def gradio_inference(dna_sequence, run_mapping):
203
  return summary, "\n".join(stats_lines), context_output, ""
204
 
205
  # --- THE UI LAYOUT ---
206
- with gr.Blocks(theme=gr.themes.Soft(), title="🧬 The Genomic Oracle 🧬") as demo:
207
  # The Integrated Landing Page
208
  gr.Markdown(
209
  """
 
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
+ # Because "import spaces" is not called yet, PyTorch is safe from the Meta Device!
17
+ print("Waking up the Genomic Oracle... Loading models safely into CPU RAM.\n")
18
+
19
+ # A. Kadir's Gatekeeper
20
+ clf_coding = joblib.load("coding_classifier_universal.joblib")
21
+
22
+ # B. Base DNABERT
23
+ tokenizer_base = AutoTokenizer.from_pretrained("DNABERT_Local", trust_remote_code=True)
24
+ model_base = AutoModel.from_pretrained("DNABERT_Local", trust_remote_code=True, low_cpu_mem_usage=False)
25
+ model_base.eval()
26
+
27
+ # C. DNABERT-2 Promoter Model
28
+ tokenizer_promoter = AutoTokenizer.from_pretrained("llm_promoter_classifier_v2", trust_remote_code=True)
29
+ model_promoter = AutoModelForSequenceClassification.from_pretrained("llm_promoter_classifier_v2", trust_remote_code=True, low_cpu_mem_usage=False)
30
+ model_promoter.eval()
31
+
32
+ # D. Multi-Feature LightGBM
33
+ lgbm_path = hf_hub_download(repo_id="Geonomic/Genomic-Oracle-Weights", filename="dnabert_lightgbm_model_feature_type.pkl")
34
+ lightgbm_model = joblib.load(lgbm_path)
35
+
36
+ # E. Custom ALiBi Lean/Obese BERT
37
+ tokenizer_pheno = AutoTokenizer.from_pretrained("Geonomic/Genomic-Oracle-Weights", trust_remote_code=True)
38
+ model_pheno = AutoModelForSequenceClassification.from_pretrained("Geonomic/Genomic-Oracle-Weights", trust_remote_code=True, low_cpu_mem_usage=False)
39
+ model_pheno.eval()
40
 
41
  # Structural Feature Dictionary
42
  FEATURE_DICT = {
 
47
  # ==============================================
48
  # 2. CORE INFERENCE ENGINE (ZeroGPU Accelerated)
49
  # ==============================================
50
+ import spaces # <--- THE MAGIC DELAY: We import ZeroGPU ONLY AFTER models are safely loaded!
51
+
52
+ @spaces.GPU # This tells Hugging Face to teleport the CPU models to the A100 GPU dynamically
53
  def run_deep_learning_cascade(dna_sequence):
54
  device = torch.device("cuda") # Wakes up the A100 connection
55
  clean_seq = "".join(dna_sequence.split()).upper()
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  # --- LEVEL 1: Base Embedding & Kadir's Gatekeeper ---
58
  inputs = tokenizer_base([clean_seq], return_tensors="pt", max_length=300, truncation=True, padding=True)
59
  inputs = {k: v.to(device) for k, v in inputs.items()}
 
207
  return summary, "\n".join(stats_lines), context_output, ""
208
 
209
  # --- THE UI LAYOUT ---
210
+ with gr.Blocks(theme=gr.themes.Soft(), title="🧬 The Genomic Oracle") as demo:
211
  # The Integrated Landing Page
212
  gr.Markdown(
213
  """