re-type commited on
Commit
0addca3
·
verified ·
1 Parent(s): 81de719

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -10
app.py CHANGED
@@ -730,7 +730,6 @@ def run_pipeline(dna_input, similarity_score=95.0, build_ml_tree=False):
730
  None, None, None, error_msg
731
  )
732
 
733
- # --- Gradio Interface ---
734
  # --- Gradio Interface ---
735
  def create_interface():
736
  """Create the Gradio interface with enhanced layout and features"""
@@ -863,10 +862,10 @@ def create_interface():
863
  )
864
 
865
  # Tree visualization
866
- gr.Markdown("### 🌲 Phylogenetic Tree Visualization")
867
  tree_html = gr.HTML(
868
  label="Interactive Tree",
869
- value="<p>Click 'Open Tree' to view the phylogenetic tree in your browser after running analysis.</p>"
870
  )
871
  open_tree_btn = gr.Button("🌳 Open Tree", variant="secondary")
872
 
@@ -884,7 +883,7 @@ def create_interface():
884
  )
885
 
886
  html_file = gr.File(
887
- label="Interactive Tree (HTML)",
888
  interactive=False
889
  )
890
 
@@ -940,7 +939,7 @@ def create_interface():
940
  ### Output Files
941
  - **Aligned FASTA**: Multiple sequence alignment in FASTA format
942
  - **Tree File**: Newick format phylogenetic tree
943
- - **HTML Tree**: Interactive visualization for web browsers
944
 
945
  ### Troubleshooting
946
 
@@ -980,11 +979,21 @@ def create_interface():
980
  def open_tree(html_file):
981
  if html_file and os.path.exists(html_file):
982
  try:
983
- # Serve the file via Gradio's static file serving (temporary URL)
984
- return gr.File.update(value=html_file, visible=True), gr.update(value=f"<script>window.open('{html_file}', '_blank');</script>")
 
 
 
 
 
 
 
 
 
 
985
  except Exception as e:
986
- return gr.File.update(value=None, visible=False), gr.update(value=f"<p>Error opening tree: {str(e)}. Please download and open the file manually.</p>")
987
- return gr.File.update(value=None, visible=False), gr.update(value="<p>No tree file available. Run analysis to generate one.</p>")
988
 
989
  # Connect events
990
  run_btn.click(
@@ -1005,7 +1014,7 @@ def create_interface():
1005
  open_tree_btn.click(
1006
  fn=open_tree,
1007
  inputs=[html_file],
1008
- outputs=[html_file, tree_html]
1009
  )
1010
 
1011
  # Example data loading
 
730
  None, None, None, error_msg
731
  )
732
 
 
733
  # --- Gradio Interface ---
734
  def create_interface():
735
  """Create the Gradio interface with enhanced layout and features"""
 
862
  )
863
 
864
  # Tree visualization
865
+ gr.Markdown("### 🌲 Phylogenetic Tree Visualization (ML Simplified Tree)")
866
  tree_html = gr.HTML(
867
  label="Interactive Tree",
868
+ value="<p>Click 'Open Tree' to view the ML Simplified Tree in your browser after running analysis.</p>"
869
  )
870
  open_tree_btn = gr.Button("🌳 Open Tree", variant="secondary")
871
 
 
883
  )
884
 
885
  html_file = gr.File(
886
+ label="Interactive Tree (HTML) - ML Simplified Tree",
887
  interactive=False
888
  )
889
 
 
939
  ### Output Files
940
  - **Aligned FASTA**: Multiple sequence alignment in FASTA format
941
  - **Tree File**: Newick format phylogenetic tree
942
+ - **HTML Tree**: Interactive visualization for web browsers (ML Simplified Tree)
943
 
944
  ### Troubleshooting
945
 
 
979
  def open_tree(html_file):
980
  if html_file and os.path.exists(html_file):
981
  try:
982
+ # Generate a temporary URL for the file using Gradio's file serving in a Space
983
+ from gradio.utils import get_space
984
+ space_url = get_space() # Gets the Space URL if running in a Space
985
+ if space_url:
986
+ # Construct a URL to the file (relative path from the Space root)
987
+ import os
988
+ file_path = os.path.relpath(html_file, os.getcwd())
989
+ file_url = f"{space_url}/file={file_path}"
990
+ return gr.update(value=f"<script>window.open('{file_url}', '_blank');</script>")
991
+ else:
992
+ # Fallback for local testing or if space_url fails
993
+ return gr.update(value=f"<p>Please download the file and open it in your browser: <a href='/file={html_file}' download>Download</a></p>")
994
  except Exception as e:
995
+ return gr.update(value=f"<p>Error opening tree: {str(e)}. Please download and open the file manually: <a href='/file={html_file}' download>Download</a></p>")
996
+ return gr.update(value="<p>No tree file available. Run analysis to generate one.</p>")
997
 
998
  # Connect events
999
  run_btn.click(
 
1014
  open_tree_btn.click(
1015
  fn=open_tree,
1016
  inputs=[html_file],
1017
+ outputs=[tree_html]
1018
  )
1019
 
1020
  # Example data loading