re-type commited on
Commit
4ce6bb6
·
verified ·
1 Parent(s): c3d2d01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -310,9 +310,7 @@ def read_fasta_file(file_obj):
310
  except Exception as e:
311
  logger.error(f"Failed to read FASTA file: {e}", exc_info=True)
312
  return ""
313
- import gradio as gr
314
 
315
- @gr.queue()
316
  def run_pipeline(dna_input, similarity_score=95.0, build_ml_tree=False):
317
  try:
318
  dna_input = dna_input.upper().strip()
@@ -404,7 +402,6 @@ Tree Analysis: {'✅ OK' if 'Found' in simplified_ml_output else '❌ Failed'}
404
  error_msg = f"❌ Pipeline Error: {str(e)}"
405
  return error_msg, "", "", "", "", None, None, None, None, error_msg, error_msg, None, None
406
 
407
- @gr.queue()
408
  async def run_pipeline_from_file(fasta_file_obj, similarity_score, build_ml_tree):
409
  temp_file_path = None
410
  try:
@@ -433,6 +430,7 @@ async def run_pipeline_from_file(fasta_file_obj, similarity_score, build_ml_tree
433
  os.unlink(temp_file_path)
434
  except Exception as e:
435
  logger.warning(f"Failed to delete temp file {temp_file_path}: {e}")
 
436
  # --- Pydantic Models ---
437
  class AnalysisRequest(BaseModel):
438
  sequence: str
@@ -760,10 +758,14 @@ def create_gradio_interface():
760
 
761
  # --- Application Startup ---
762
  def run_application():
 
 
 
763
  try:
764
  gradio_app = create_gradio_interface()
765
  gradio_app = gr.mount_gradio_app(app, gradio_app, path="/gradio")
766
  logger.info("🚀 Starting Gene Analysis Pipeline...")
 
767
  logger.info("📊 FastAPI docs available at: http://localhost:7860/docs")
768
  logger.info("🧬 Gradio interface available at: http://localhost:7860/gradio")
769
  uvicorn.run(
@@ -777,6 +779,7 @@ def run_application():
777
  try:
778
  logger.info("🔄 Falling back to Gradio-only mode...")
779
  gradio_app = create_gradio_interface()
 
780
  gradio_app.launch(
781
  server_name="0.0.0.0",
782
  server_port=7860,
@@ -786,6 +789,18 @@ def run_application():
786
  except Exception as fallback_error:
787
  logger.error(f"Fallback failed: {fallback_error}", exc_info=True)
788
  print("❌ Application failed to start. Check logs for details.")
 
 
 
 
 
 
 
 
 
 
 
 
789
 
790
  # --- Main Entry Point ---
791
  if __name__ == "__main__":
 
310
  except Exception as e:
311
  logger.error(f"Failed to read FASTA file: {e}", exc_info=True)
312
  return ""
 
313
 
 
314
  def run_pipeline(dna_input, similarity_score=95.0, build_ml_tree=False):
315
  try:
316
  dna_input = dna_input.upper().strip()
 
402
  error_msg = f"❌ Pipeline Error: {str(e)}"
403
  return error_msg, "", "", "", "", None, None, None, None, error_msg, error_msg, None, None
404
 
 
405
  async def run_pipeline_from_file(fasta_file_obj, similarity_score, build_ml_tree):
406
  temp_file_path = None
407
  try:
 
430
  os.unlink(temp_file_path)
431
  except Exception as e:
432
  logger.warning(f"Failed to delete temp file {temp_file_path}: {e}")
433
+
434
  # --- Pydantic Models ---
435
  class AnalysisRequest(BaseModel):
436
  sequence: str
 
758
 
759
  # --- Application Startup ---
760
  def run_application():
761
+ e = None # Predefine e to avoid free variable error
762
+ fallback_error = None # Predefine fallback_error for clarity
763
+ gradio_app = None # Predefine gradio_app for cleanup
764
  try:
765
  gradio_app = create_gradio_interface()
766
  gradio_app = gr.mount_gradio_app(app, gradio_app, path="/gradio")
767
  logger.info("🚀 Starting Gene Analysis Pipeline...")
768
+ logger.warning("⚠️ Running without request queuing. Concurrent requests may block.")
769
  logger.info("📊 FastAPI docs available at: http://localhost:7860/docs")
770
  logger.info("🧬 Gradio interface available at: http://localhost:7860/gradio")
771
  uvicorn.run(
 
779
  try:
780
  logger.info("🔄 Falling back to Gradio-only mode...")
781
  gradio_app = create_gradio_interface()
782
+ logger.warning("⚠️ Running without request queuing in fallback mode.")
783
  gradio_app.launch(
784
  server_name="0.0.0.0",
785
  server_port=7860,
 
789
  except Exception as fallback_error:
790
  logger.error(f"Fallback failed: {fallback_error}", exc_info=True)
791
  print("❌ Application failed to start. Check logs for details.")
792
+ finally:
793
+ if gradio_app:
794
+ try:
795
+ gradio_app.close()
796
+ except Exception as close_error:
797
+ logger.warning(f"Failed to close Gradio app in fallback: {close_error}")
798
+ finally:
799
+ if gradio_app:
800
+ try:
801
+ gradio_app.close()
802
+ except Exception as close_error:
803
+ logger.warning(f"Failed to close Gradio app: {close_error}")
804
 
805
  # --- Main Entry Point ---
806
  if __name__ == "__main__":