pskeshu Claude commited on
Commit
596cd10
Β·
1 Parent(s): e53b543

πŸ› Add comprehensive logging and remove CMPO mapping

Browse files

- Add detailed logging throughout analysis pipeline for debugging
- Remove CMPO phenotype mapping to simplify app and focus on 4-stage VLM
- Add error traceback display for better debugging
- Add status messages during analysis process

πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +30 -30
app.py CHANGED
@@ -10,6 +10,15 @@ from pathlib import Path
10
  import numpy as np
11
  from PIL import Image
12
  import random
 
 
 
 
 
 
 
 
 
13
 
14
  # Setup page
15
  st.set_page_config(
@@ -112,8 +121,7 @@ sys.path.append(str(Path(__file__).parent))
112
  try:
113
  from anton.core.pipeline import AnalysisPipeline
114
  from anton.utils.image_io import ImageLoader
115
- from anton.cmpo.mapping import map_to_cmpo
116
- from anton.cmpo.ontology import CMPOOntology
117
  anton_available = True
118
  except ImportError as e:
119
  anton_available = False
@@ -214,12 +222,19 @@ if current_image is not None:
214
 
215
  # Run analysis
216
  if analyze_btn:
 
 
 
217
  # Check API keys
218
  vlm_provider = "mock"
219
  if os.getenv('GOOGLE_API_KEY'):
220
  vlm_provider = "gemini"
 
221
  elif os.getenv('ANTHROPIC_API_KEY'):
222
  vlm_provider = "claude"
 
 
 
223
 
224
  # Configure pipeline
225
  if use_sample and sample_images:
@@ -229,22 +244,28 @@ if current_image is not None:
229
  "protein": "FKHR-GFP",
230
  "readout": "nuclear_vs_cytoplasmic_localization"
231
  }
 
232
  else:
233
  biological_context = {
234
  "experiment_type": "general_microscopy",
235
  "readout": "cellular_morphology_and_phenotypes"
236
  }
 
237
 
238
  config = {
239
  "vlm_provider": vlm_provider,
240
  "biological_context": biological_context
241
  }
 
242
 
243
  # Run analysis
244
  with st.spinner("Analyzing..."):
245
  try:
 
246
  pipeline = AnalysisPipeline(config)
 
247
  results = pipeline.run_pipeline_sync(image_to_analyze)
 
248
 
249
  # Display results
250
  st.markdown('<div class="results-container">', unsafe_allow_html=True)
@@ -272,33 +293,8 @@ if current_image is not None:
272
 
273
  st.write(content[:1000] + "..." if len(content) > 1000 else content)
274
 
275
- # CMPO Phenotypes
276
- try:
277
- cmpo_mapper = CMPOOntology()
278
- all_cmpo_results = []
279
-
280
- for stage_name, stage_key in stages:
281
- if stage_key in results and results[stage_key]:
282
- stage_data = results[stage_key]
283
- stage_text = stage_data.get('description',
284
- stage_data.get('segmentation_guidance',
285
- stage_data.get('population_summary', '')))
286
-
287
- if stage_text and len(stage_text) > 50:
288
- cmpo_context = 'protein_localization' if use_sample else 'general_microscopy'
289
- cmpo_results = map_to_cmpo(stage_text, cmpo_mapper, context=cmpo_context)
290
- if cmpo_results:
291
- all_cmpo_results.extend(cmpo_results[:2])
292
-
293
- if all_cmpo_results:
294
- st.markdown("### 🧬 Detected Phenotypes")
295
- for mapping in all_cmpo_results[:5]:
296
- confidence = mapping.get('confidence', 0)
297
- icon = "🟒" if confidence >= 4.5 else "🟑" if confidence >= 3.5 else "🟠"
298
- st.markdown(f"{icon} **{mapping.get('term_name', 'Unknown')}** ({confidence:.1f}/5)")
299
-
300
- except Exception as e:
301
- st.warning("Phenotype classification unavailable")
302
 
303
  st.markdown('</div>', unsafe_allow_html=True)
304
 
@@ -310,7 +306,11 @@ if current_image is not None:
310
  pass
311
 
312
  except Exception as e:
313
- st.error(f"Analysis failed: {str(e)}")
 
 
 
 
314
  else:
315
  st.markdown('<div class="upload-section">', unsafe_allow_html=True)
316
  st.markdown("**Upload an image or select a sample to begin analysis**")
 
10
  import numpy as np
11
  from PIL import Image
12
  import random
13
+ import logging
14
+ import traceback
15
+
16
+ # Setup logging
17
+ logging.basicConfig(
18
+ level=logging.INFO,
19
+ format='%(asctime)s - %(levelname)s - %(message)s'
20
+ )
21
+ logger = logging.getLogger(__name__)
22
 
23
  # Setup page
24
  st.set_page_config(
 
121
  try:
122
  from anton.core.pipeline import AnalysisPipeline
123
  from anton.utils.image_io import ImageLoader
124
+ # CMPO mapping removed for simplicity
 
125
  anton_available = True
126
  except ImportError as e:
127
  anton_available = False
 
222
 
223
  # Run analysis
224
  if analyze_btn:
225
+ logger.info("Analysis button pressed")
226
+ st.info("Starting analysis...")
227
+
228
  # Check API keys
229
  vlm_provider = "mock"
230
  if os.getenv('GOOGLE_API_KEY'):
231
  vlm_provider = "gemini"
232
+ logger.info("Using Gemini VLM provider")
233
  elif os.getenv('ANTHROPIC_API_KEY'):
234
  vlm_provider = "claude"
235
+ logger.info("Using Claude VLM provider")
236
+ else:
237
+ logger.info("Using mock VLM provider (no API keys found)")
238
 
239
  # Configure pipeline
240
  if use_sample and sample_images:
 
244
  "protein": "FKHR-GFP",
245
  "readout": "nuclear_vs_cytoplasmic_localization"
246
  }
247
+ logger.info("Using sample image context: protein translocation")
248
  else:
249
  biological_context = {
250
  "experiment_type": "general_microscopy",
251
  "readout": "cellular_morphology_and_phenotypes"
252
  }
253
+ logger.info("Using general microscopy context")
254
 
255
  config = {
256
  "vlm_provider": vlm_provider,
257
  "biological_context": biological_context
258
  }
259
+ logger.info(f"Pipeline config: {config}")
260
 
261
  # Run analysis
262
  with st.spinner("Analyzing..."):
263
  try:
264
+ logger.info(f"Creating pipeline with image: {image_to_analyze}")
265
  pipeline = AnalysisPipeline(config)
266
+ logger.info("Pipeline created, starting analysis...")
267
  results = pipeline.run_pipeline_sync(image_to_analyze)
268
+ logger.info(f"Analysis completed. Results keys: {list(results.keys()) if results else 'None'}")
269
 
270
  # Display results
271
  st.markdown('<div class="results-container">', unsafe_allow_html=True)
 
293
 
294
  st.write(content[:1000] + "..." if len(content) > 1000 else content)
295
 
296
+ # Skip CMPO mapping for now
297
+ logger.info("Analysis results displayed successfully")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
 
299
  st.markdown('</div>', unsafe_allow_html=True)
300
 
 
306
  pass
307
 
308
  except Exception as e:
309
+ error_msg = f"Analysis failed: {str(e)}"
310
+ logger.error(error_msg)
311
+ logger.error(f"Full traceback: {traceback.format_exc()}")
312
+ st.error(error_msg)
313
+ st.code(traceback.format_exc())
314
  else:
315
  st.markdown('<div class="upload-section">', unsafe_allow_html=True)
316
  st.markdown("**Upload an image or select a sample to begin analysis**")