re-type commited on
Commit
fa1658a
·
verified ·
1 Parent(s): c55e9fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -19
app.py CHANGED
@@ -713,21 +713,30 @@ def create_gradio_interface():
713
  value="<div style='text-align: center; color: #666; padding: 20px;'>No report generated yet. Run analysis to see results.</div>"
714
  )
715
 
716
- # Event handlers
717
  def handle_analysis_output(*outputs):
718
- boundary_output, keras_output, ml_tree_output, simplified_ml_output, summary_output, aligned_file, phy_file, _, _, tree_html_content, report_html_content, tree_html_path, report_html_path = outputs
719
- return (
720
- boundary_output, keras_output, ml_tree_output, simplified_ml_output, summary_output,
721
- gr.File.update(value=aligned_file, visible=aligned_file is not None),
722
- gr.File.update(value=phy_file, visible=phy_file is not None),
723
- gr.File.update(value=tree_html_path, visible=tree_html_path is not None),
724
- gr.File.update(value=report_html_path, visible=report_html_path is not None),
725
- tree_html_content,
726
- report_html_content
727
- )
 
 
 
 
 
 
 
 
 
728
 
729
  analyze_btn.click(
730
- fn=run_pipeline,
731
  inputs=[dna_input, similarity_score, build_ml_tree],
732
  outputs=[
733
  boundary_output, keras_output, ml_tree_output, tree_analysis_output, summary_output,
@@ -736,7 +745,7 @@ def create_gradio_interface():
736
  )
737
 
738
  analyze_file_btn.click(
739
- fn=run_pipeline_from_file,
740
  inputs=[file_input, file_similarity_score, file_build_ml_tree],
741
  outputs=[
742
  boundary_output, keras_output, ml_tree_output, tree_analysis_output, summary_output,
@@ -784,6 +793,16 @@ def run_application():
784
  try:
785
  main_gradio_app = create_gradio_interface()
786
  main_gradio_app = gr.mount_gradio_app(app, main_gradio_app, path="/gradio")
 
 
 
 
 
 
 
 
 
 
787
  logger.info("🚀 Starting Gene Analysis Pipeline...")
788
  logger.warning("⚠️ Running without request queuing. Concurrent requests may block.")
789
  logger.info("📊 FastAPI docs available at: http://localhost:7860/docs")
@@ -792,24 +811,23 @@ def run_application():
792
  app,
793
  host="0.0.0.0",
794
  port=7860,
795
- log_level="info"
 
796
  )
797
  except Exception as main_error:
798
  logger.error(f"Application startup failed: {main_error}", exc_info=True)
799
  try:
800
  logger.info("🔄 Falling back to Gradio-only mode...")
801
  fallback_gradio_app = create_gradio_interface()
802
- logger.warning("⚠️ Running without request queuing in fallback mode.")
803
  fallback_gradio_app.launch(
804
  server_name="0.0.0.0",
805
  server_port=7860,
806
- share=False,
807
- debug=False
808
  )
809
  except Exception as fallback_error:
810
  logger.error(f"Fallback failed: {fallback_error}", exc_info=True)
811
- print("❌ Application failed to start. Check logs for details.")
812
- if __name__ == "__main__":
813
  print("🧬 Gene Analysis Pipeline Starting...")
814
  print("=" * 50)
815
  print("🔍 Checking system components...")
 
713
  value="<div style='text-align: center; color: #666; padding: 20px;'>No report generated yet. Run analysis to see results.</div>"
714
  )
715
 
716
+ # Event handlers with enhanced logging
717
  def handle_analysis_output(*outputs):
718
+ try:
719
+ boundary_output, keras_output, ml_tree_output, simplified_ml_output, summary_output, aligned_file, phy_file, _, _, tree_html_content, report_html_content, tree_html_path, report_html_path = outputs
720
+ return (
721
+ boundary_output, keras_output, ml_tree_output, simplified_ml_output, summary_output,
722
+ gr.File.update(value=aligned_file, visible=aligned_file is not None),
723
+ gr.File.update(value=phy_file, visible=phy_file is not None),
724
+ gr.File.update(value=tree_html_path, visible=tree_html_path is not None),
725
+ gr.File.update(value=report_html_path, visible=report_html_path is not None),
726
+ tree_html_content,
727
+ report_html_content
728
+ )
729
+ except Exception as handler_error:
730
+ logger.error(f"Error in handle_analysis_output: {handler_error}", exc_info=True)
731
+ return (
732
+ f"Error: {str(handler_error)}", "", "", "", "",
733
+ gr.File.update(visible=False), gr.File.update(visible=False),
734
+ gr.File.update(visible=False), gr.File.update(visible=False),
735
+ "", ""
736
+ )
737
 
738
  analyze_btn.click(
739
+ fn=lambda *args: handle_analysis_output(run_pipeline(*args)),
740
  inputs=[dna_input, similarity_score, build_ml_tree],
741
  outputs=[
742
  boundary_output, keras_output, ml_tree_output, tree_analysis_output, summary_output,
 
745
  )
746
 
747
  analyze_file_btn.click(
748
+ fn=lambda *args: handle_analysis_output(run_pipeline_from_file(*args)),
749
  inputs=[file_input, file_similarity_score, file_build_ml_tree],
750
  outputs=[
751
  boundary_output, keras_output, ml_tree_output, tree_analysis_output, summary_output,
 
793
  try:
794
  main_gradio_app = create_gradio_interface()
795
  main_gradio_app = gr.mount_gradio_app(app, main_gradio_app, path="/gradio")
796
+ logger.info("🧬 Gene Analysis Pipeline Starting...")
797
+ logger.info("=" * 50)
798
+ logger.info("🔍 Checking system components...")
799
+ logger.info(f"🤖 Boundary Model: {'✅ Loaded' if boundary_model else '❌ Missing'}")
800
+ logger.info(f"🧠 Keras Model: {'✅ Loaded' if keras_model else '❌ Missing'}")
801
+ logger.info(f"🌳 Tree Analyzer: {'✅ Loaded' if analyzer else '❌ Missing'}")
802
+ mafft_available, iqtree_available = check_tool_availability()
803
+ logger.info(f"🧬 MAFFT: {'✅ Available' if mafft_available else '❌ Missing'}")
804
+ logger.info(f"🌲 IQ-TREE: {'✅ Available' if iqtree_available else '❌ Missing'}")
805
+ logger.info("=" * 50)
806
  logger.info("🚀 Starting Gene Analysis Pipeline...")
807
  logger.warning("⚠️ Running without request queuing. Concurrent requests may block.")
808
  logger.info("📊 FastAPI docs available at: http://localhost:7860/docs")
 
811
  app,
812
  host="0.0.0.0",
813
  port=7860,
814
+ log_level="info",
815
+ access_log=True
816
  )
817
  except Exception as main_error:
818
  logger.error(f"Application startup failed: {main_error}", exc_info=True)
819
  try:
820
  logger.info("🔄 Falling back to Gradio-only mode...")
821
  fallback_gradio_app = create_gradio_interface()
822
+ logger.info("🧬 Gradio interface available at: http://localhost:7860")
823
  fallback_gradio_app.launch(
824
  server_name="0.0.0.0",
825
  server_port=7860,
826
+ prevent_thread_lock=True
 
827
  )
828
  except Exception as fallback_error:
829
  logger.error(f"Fallback failed: {fallback_error}", exc_info=True)
830
+ print("❌ Application failed to start. Check logs for details.")if __name__ == "__main__":
 
831
  print("🧬 Gene Analysis Pipeline Starting...")
832
  print("=" * 50)
833
  print("🔍 Checking system components...")