Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -785,60 +785,6 @@ def run_pipeline(dna_input, similarity_score=95.0, build_ml_tree=False):
|
|
| 785 |
return error_msg, "", "", "", "", None, None, None, None, error_msg, error_msg
|
| 786 |
|
| 787 |
|
| 788 |
-
def run_pipeline(dna_sequence: str, similarity_threshold: float, do_phylogeny: bool):
|
| 789 |
-
try:
|
| 790 |
-
# Step 1: F Gene Extraction
|
| 791 |
-
f_gene_seq = boundary_model.predict_sequence(dna_sequence)
|
| 792 |
-
if not f_gene_seq:
|
| 793 |
-
return "❌ No F gene found", "", "", "", "F gene extraction failed", None, None, None, None, "", ""
|
| 794 |
-
|
| 795 |
-
# Step 2: F Gene Validation
|
| 796 |
-
is_valid = keras_model.validate_sequence(f_gene_seq)
|
| 797 |
-
keras_result = "✅ Valid F gene" if is_valid else "❌ Not an F gene"
|
| 798 |
-
|
| 799 |
-
# Step 3: Save input to temp FASTA
|
| 800 |
-
temp_fasta_path = os.path.join(BASE_DIR, "input_temp.fasta")
|
| 801 |
-
SeqIO.write(SeqRecord(Seq(f_gene_seq), id="query", description=""), temp_fasta_path, "fasta")
|
| 802 |
-
|
| 803 |
-
# Step 4: Phylogenetic Placement (if enabled)
|
| 804 |
-
tree_result = ""
|
| 805 |
-
analysis_status = ""
|
| 806 |
-
summary_text = ""
|
| 807 |
-
align_file = tree_file = html_file = report_file = None
|
| 808 |
-
tree_html = report_html = "<div style='color:gray'>Skipped</div>"
|
| 809 |
-
|
| 810 |
-
if do_phylogeny:
|
| 811 |
-
# Run analyzer (wraps MAFFT + IQ-TREE + HTML visualizer)
|
| 812 |
-
outputs = analyzer.analyze(
|
| 813 |
-
input_fasta=temp_fasta_path,
|
| 814 |
-
similarity=similarity_threshold / 100.0,
|
| 815 |
-
output_dir=BASE_DIR
|
| 816 |
-
)
|
| 817 |
-
tree_result = outputs["tree_info"]
|
| 818 |
-
analysis_status = outputs["tree_status"]
|
| 819 |
-
summary_text = outputs["summary"]
|
| 820 |
-
align_file = outputs["alignment"]
|
| 821 |
-
tree_file = outputs["tree"]
|
| 822 |
-
html_file = outputs["tree_html"]
|
| 823 |
-
report_file = outputs["report"]
|
| 824 |
-
tree_html = Path(html_file).read_text() if html_file else tree_html
|
| 825 |
-
report_html = Path(report_file).read_text() if report_file else report_html
|
| 826 |
-
|
| 827 |
-
return f_gene_seq, keras_result, tree_result, analysis_status, summary_text, align_file, tree_file, html_file, report_file, tree_html, report_html
|
| 828 |
-
|
| 829 |
-
except Exception as e:
|
| 830 |
-
logging.error(f"Pipeline Error: {e}")
|
| 831 |
-
return "❌ Error during processing", "", "", "", f"Error: {e}", None, None, None, None, "", ""
|
| 832 |
-
|
| 833 |
-
def run_pipeline_from_file(fasta_path, similarity_threshold: float, do_phylogeny: bool):
|
| 834 |
-
try:
|
| 835 |
-
seq_record = next(SeqIO.parse(fasta_path, "fasta"))
|
| 836 |
-
dna_sequence = str(seq_record.seq)
|
| 837 |
-
return run_pipeline(dna_sequence, similarity_threshold, do_phylogeny)
|
| 838 |
-
except Exception as e:
|
| 839 |
-
logging.error(f"File Pipeline Error: {e}")
|
| 840 |
-
return "❌ Invalid FASTA", "", "", "", f"Error: {e}", None, None, None, None, "", ""
|
| 841 |
-
|
| 842 |
# --- Gradio Interface ---
|
| 843 |
def create_interface():
|
| 844 |
"""Create and configure the Gradio interface"""
|
|
@@ -1104,12 +1050,11 @@ if __name__ == "__main__":
|
|
| 1104 |
|
| 1105 |
# Create and launch interface
|
| 1106 |
iface = create_interface()
|
| 1107 |
-
iface.
|
| 1108 |
share=False, # Set to True if you want to create a public link
|
| 1109 |
server_name="0.0.0.0", # Allow connections from any IP
|
| 1110 |
server_port=7860, # Default Gradio port
|
| 1111 |
-
show_error=True
|
| 1112 |
-
ssr_mode=False # Disable experimental SSR (prevents 405 error)
|
| 1113 |
)
|
| 1114 |
|
| 1115 |
except Exception as e:
|
|
|
|
| 785 |
return error_msg, "", "", "", "", None, None, None, None, error_msg, error_msg
|
| 786 |
|
| 787 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 788 |
# --- Gradio Interface ---
|
| 789 |
def create_interface():
|
| 790 |
"""Create and configure the Gradio interface"""
|
|
|
|
| 1050 |
|
| 1051 |
# Create and launch interface
|
| 1052 |
iface = create_interface()
|
| 1053 |
+
iface.launch(
|
| 1054 |
share=False, # Set to True if you want to create a public link
|
| 1055 |
server_name="0.0.0.0", # Allow connections from any IP
|
| 1056 |
server_port=7860, # Default Gradio port
|
| 1057 |
+
show_error=True # Show errors in the interface
|
|
|
|
| 1058 |
)
|
| 1059 |
|
| 1060 |
except Exception as e:
|