re-type commited on
Commit
94ee67c
·
verified ·
1 Parent(s): 9b7e7f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -655,6 +655,9 @@ def run_pipeline(dna_input, similarity_score=95.0, build_ml_tree=False):
655
  else:
656
  ml_tree_output = "Phylogenetic placement skipped (not requested)"
657
 
 
 
 
658
  # Step 4: NEW Simplified Tree Analysis (using the new analyzer API)
659
  html_file = None
660
  tree_html_content = "No tree generated"
@@ -682,9 +685,17 @@ def run_pipeline(dna_input, similarity_score=95.0, build_ml_tree=False):
682
  shutil.copy2(html_path, final_html_path)
683
  html_file = final_html_path
684
 
685
- # Read HTML content for display
686
- with open(html_path, 'r', encoding='utf-8') as f:
687
- tree_html_content = f.read()
 
 
 
 
 
 
 
 
688
 
689
  simplified_ml_output = tree_result
690
  logging.info(f"Tree analysis completed successfully: {html_filename}")
@@ -697,12 +708,12 @@ def run_pipeline(dna_input, similarity_score=95.0, build_ml_tree=False):
697
 
698
  else:
699
  simplified_ml_output = tree_result # Error message
700
- tree_html_content = f"<div style='color: red;'>{tree_result}</div>"
701
 
702
  except Exception as e:
703
  error_msg = f"❌ Tree analysis failed: {str(e)}"
704
  simplified_ml_output = error_msg
705
- tree_html_content = f"<div style='color: red;'>{error_msg}</div>"
706
  logging.error(f"Tree analysis failed: {e}")
707
  else:
708
  if not analyzer:
@@ -712,7 +723,7 @@ def run_pipeline(dna_input, similarity_score=95.0, build_ml_tree=False):
712
  else:
713
  simplified_ml_output = "❌ No processed sequence available for tree analysis"
714
 
715
- tree_html_content = f"<div style='color: orange;'>{simplified_ml_output}</div>"
716
 
717
  # Final summary
718
  summary_output = f"""
@@ -992,7 +1003,6 @@ def create_interface():
992
 
993
  return iface
994
 
995
- # --- Main Execution ---
996
  # --- Main Execution ---
997
  if __name__ == "__main__":
998
  try:
@@ -1018,10 +1028,12 @@ if __name__ == "__main__":
1018
  # Create and launch interface
1019
  iface = create_interface()
1020
  iface.launch(
1021
- share=False, # Set to True if you want to create a public link
1022
  server_name="0.0.0.0", # Allow connections from any IP
1023
  server_port=7860, # Default Gradio port
1024
- show_error=True # Show errors in the interface
 
 
1025
  )
1026
 
1027
  except Exception as e:
 
655
  else:
656
  ml_tree_output = "Phylogenetic placement skipped (not requested)"
657
 
658
+ # Replace the tree analysis section in your run_pipeline function (around line 500-600)
659
+ # Find this part and replace it:
660
+
661
  # Step 4: NEW Simplified Tree Analysis (using the new analyzer API)
662
  html_file = None
663
  tree_html_content = "No tree generated"
 
685
  shutil.copy2(html_path, final_html_path)
686
  html_file = final_html_path
687
 
688
+ # FIXED: Instead of reading HTML content, create a simple link
689
+ tree_html_content = f"""
690
+ <div style='text-align: center; padding: 20px; background: #f0f9ff; border: 2px solid #0ea5e9; border-radius: 10px;'>
691
+ <h3 style='color: #0c4a6e; margin: 0 0 15px 0;'>🌳 Interactive Phylogenetic Tree Generated</h3>
692
+ <p style='color: #164e63; margin-bottom: 15px;'>Your interactive tree has been generated successfully!</p>
693
+ <a href='{final_html_path}' target='_blank' style='display: inline-block; padding: 10px 20px; background: #0ea5e9; color: white; text-decoration: none; border-radius: 5px; font-weight: bold;'>
694
+ 🔗 Open Interactive Tree in New Tab
695
+ </a>
696
+ <p style='color: #64748b; margin-top: 10px; font-size: 0.9em;'>Note: Download the HTML file below to view the tree locally</p>
697
+ </div>
698
+ """
699
 
700
  simplified_ml_output = tree_result
701
  logging.info(f"Tree analysis completed successfully: {html_filename}")
 
708
 
709
  else:
710
  simplified_ml_output = tree_result # Error message
711
+ tree_html_content = f"<div style='color: red; padding: 20px; background: #fef2f2; border: 2px solid #ef4444; border-radius: 10px;'>{tree_result}</div>"
712
 
713
  except Exception as e:
714
  error_msg = f"❌ Tree analysis failed: {str(e)}"
715
  simplified_ml_output = error_msg
716
+ tree_html_content = f"<div style='color: red; padding: 20px; background: #fef2f2; border: 2px solid #ef4444; border-radius: 10px;'>{error_msg}</div>"
717
  logging.error(f"Tree analysis failed: {e}")
718
  else:
719
  if not analyzer:
 
723
  else:
724
  simplified_ml_output = "❌ No processed sequence available for tree analysis"
725
 
726
+ tree_html_content = f"<div style='color: orange; padding: 20px; background: #fffbeb; border: 2px solid #f59e0b; border-radius: 10px;'>{simplified_ml_output}</div>"
727
 
728
  # Final summary
729
  summary_output = f"""
 
1003
 
1004
  return iface
1005
 
 
1006
  # --- Main Execution ---
1007
  if __name__ == "__main__":
1008
  try:
 
1028
  # Create and launch interface
1029
  iface = create_interface()
1030
  iface.launch(
1031
+ share=False, # Set to True if you want to create a public link
1032
  server_name="0.0.0.0", # Allow connections from any IP
1033
  server_port=7860, # Default Gradio port
1034
+ show_error=True, # Show errors in the interface
1035
+ enable_queue=True, # Enable queuing for long-running tasks
1036
+ max_threads=4 # Limit concurrent processing
1037
  )
1038
 
1039
  except Exception as e: