re-type commited on
Commit
fec4802
·
verified ·
1 Parent(s): e1564ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -16
app.py CHANGED
@@ -18,22 +18,28 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(
18
  boundary_model = None
19
  keras_model = None
20
  kmer_to_index = None
 
21
  try:
22
- boundary_model = GenePredictor("best_boundary_aware_model.pth")
23
- logging.info("Boundary model loaded successfully")
24
- except FileNotFoundError as e:
25
- logging.warning(f"Boundary model not found: {e}. Skipping Boundary-Aware step.")
 
 
26
  except Exception as e:
27
- logging.error(f"Error loading Boundary model: {e}. Skipping Boundary-Aware step.")
28
  try:
29
- keras_model = load_model("best_model.keras")
30
- with open("kmer_to_index.pkl", "rb") as f:
31
- kmer_to_index = pickle.load(f)
32
- logging.info("Keras model and kmer_to_index loaded successfully")
33
- except FileNotFoundError as e:
34
- logging.warning(f"Keras model or kmer_to_index not found: {e}. Skipping Keras step.")
 
 
 
35
  except Exception as e:
36
- logging.error(f"Error loading Keras model or kmer_to_index: {e}. Skipping Keras step.")
37
 
38
  # --------- Utilities ---------
39
  def predict_with_keras(sequence):
@@ -70,7 +76,7 @@ def run_full_pipeline(dna_input):
70
  logging.error(f"Boundary model prediction failed: {e}")
71
  step1_out = dna_input
72
  else:
73
- logging.info("Boundary model skipped due to missing file")
74
 
75
  # Step 2: Keras Prediction (Optional)
76
  step2_out = step1_out # Fallback to step1_out if model missing
@@ -82,11 +88,11 @@ def run_full_pipeline(dna_input):
82
  logging.error(f"Keras prediction failed: {e}")
83
  step2_out = step1_out
84
  else:
85
- logging.info("Keras model skipped due to missing file")
86
 
87
  # Step 3: Run ML Simplified Tree using PhylogeneticTreeAnalyzer with existing CSV
88
  analyzer = ml_simplified_tree.PhylogeneticTreeAnalyzer()
89
- csv_path = "f gene clean.csv"
90
  if not os.path.exists(csv_path):
91
  ml_output = f"Error: Expected CSV file '{csv_path}' not found"
92
  logging.error(ml_output)
@@ -138,7 +144,7 @@ def run_full_pipeline(dna_input):
138
  # --------- Gradio Interface and API ---------
139
  with gr.Blocks() as gr_interface:
140
  gr.Markdown("# Sequential Phylogenetic Inference Pipeline")
141
- gr.Markdown("This pipeline generates a phylogenetic tree using the existing 'f gene clean.csv'. Model-based steps are optional if files are missing.")
142
 
143
  dna_input = gr.Textbox(label="Input DNA Sequence", placeholder="Enter DNA sequence (e.g., ATGCGTAACTAGCTAGCTAA)")
144
  submit_button = gr.Button("Generate Tree")
 
18
  boundary_model = None
19
  keras_model = None
20
  kmer_to_index = None
21
+ model_dir = "models/" # Adjust this if the models are in a different subdirectory
22
  try:
23
+ boundary_path = os.path.join(model_dir, "best_boundary_aware_model.pth")
24
+ if os.path.exists(boundary_path):
25
+ boundary_model = GenePredictor(boundary_path)
26
+ logging.info(f"Boundary model loaded successfully from {boundary_path}")
27
+ else:
28
+ logging.warning(f"Boundary model not found at {boundary_path}. Skipping Boundary-Aware step.")
29
  except Exception as e:
30
+ logging.error(f"Error loading Boundary model from {boundary_path}: {e}. Skipping Boundary-Aware step.")
31
  try:
32
+ keras_path = os.path.join(model_dir, "best_model.keras")
33
+ kmer_path = os.path.join(model_dir, "kmer_to_index.pkl")
34
+ if os.path.exists(keras_path) and os.path.exists(kmer_path):
35
+ keras_model = load_model(keras_path)
36
+ with open(kmer_path, "rb") as f:
37
+ kmer_to_index = pickle.load(f)
38
+ logging.info(f"Keras model and kmer_to_index loaded successfully from {keras_path} and {kmer_path}")
39
+ else:
40
+ logging.warning(f"Keras model or kmer_to_index not found at {keras_path} or {kmer_path}. Skipping Keras step.")
41
  except Exception as e:
42
+ logging.error(f"Error loading Keras model or kmer_to_index from {keras_path} or {kmer_path}: {e}. Skipping Keras step.")
43
 
44
  # --------- Utilities ---------
45
  def predict_with_keras(sequence):
 
76
  logging.error(f"Boundary model prediction failed: {e}")
77
  step1_out = dna_input
78
  else:
79
+ logging.info("Boundary model skipped due to missing or failed load")
80
 
81
  # Step 2: Keras Prediction (Optional)
82
  step2_out = step1_out # Fallback to step1_out if model missing
 
88
  logging.error(f"Keras prediction failed: {e}")
89
  step2_out = step1_out
90
  else:
91
+ logging.info("Keras model skipped due to missing or failed load")
92
 
93
  # Step 3: Run ML Simplified Tree using PhylogeneticTreeAnalyzer with existing CSV
94
  analyzer = ml_simplified_tree.PhylogeneticTreeAnalyzer()
95
+ csv_path = "f gene clean dataset.csv"
96
  if not os.path.exists(csv_path):
97
  ml_output = f"Error: Expected CSV file '{csv_path}' not found"
98
  logging.error(ml_output)
 
144
  # --------- Gradio Interface and API ---------
145
  with gr.Blocks() as gr_interface:
146
  gr.Markdown("# Sequential Phylogenetic Inference Pipeline")
147
+ gr.Markdown("This pipeline generates a phylogenetic tree using the existing 'f gene clean.csv'. Model files are expected in the 'models/' subdirectory and are optional.")
148
 
149
  dna_input = gr.Textbox(label="Input DNA Sequence", placeholder="Enter DNA sequence (e.g., ATGCGTAACTAGCTAGCTAA)")
150
  submit_button = gr.Button("Generate Tree")