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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -42
app.py CHANGED
@@ -730,6 +730,7 @@ 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
  def create_interface():
735
  """Create the Gradio interface with enhanced layout and features"""
@@ -746,28 +747,6 @@ def create_interface():
746
  height: 600px !important;
747
  overflow: auto;
748
  }
749
- .modal {
750
- display: none;
751
- position: fixed;
752
- top: 0;
753
- left: 0;
754
- width: 100%;
755
- height: 100%;
756
- background-color: rgba(0,0,0,0.5);
757
- }
758
- .modal-content {
759
- background-color: white;
760
- margin: 5% auto;
761
- padding: 20px;
762
- width: 80%;
763
- max-height: 80%;
764
- overflow: auto;
765
- }
766
- .close {
767
- float: right;
768
- font-size: 24px;
769
- cursor: pointer;
770
- }
771
  """
772
 
773
  with gr.Blocks(css=custom_css, title="F Gene Analysis Pipeline") as iface:
@@ -887,11 +866,9 @@ def create_interface():
887
  gr.Markdown("### 🌲 Phylogenetic Tree Visualization")
888
  tree_html = gr.HTML(
889
  label="Interactive Tree",
890
- value="<p>Click 'View Tree' to see the phylogenetic tree after running analysis.</p>"
891
  )
892
- view_tree_btn = gr.Button("👁️ View Tree", variant="secondary")
893
- tree_modal = gr.HTML(visible=False, elem_classes=["modal-content"])
894
- close_btn = gr.Button("✖️ Close", visible=False, elem_classes=["close"])
895
 
896
  # File downloads
897
  gr.Markdown("### 📁 Download Results")
@@ -1000,17 +977,14 @@ def create_interface():
1000
  def clear_inputs():
1001
  return "", None, 95.0, False, "Ready to analyze"
1002
 
1003
- def view_tree(html_file):
1004
  if html_file and os.path.exists(html_file):
1005
  try:
1006
- with open(html_file, "r", encoding='utf-8') as f:
1007
- return f.read(), gr.update(visible=True), gr.update(visible=True)
1008
  except Exception as e:
1009
- return f"<p>Error loading tree: {str(e)}</p>", gr.update(visible=True), gr.update(visible=True)
1010
- return "<p>No tree file available. Run analysis to generate one.</p>", gr.update(visible=True), gr.update(visible=True)
1011
-
1012
- def close_modal():
1013
- return gr.update(visible=False), gr.update(visible=False)
1014
 
1015
  # Connect events
1016
  run_btn.click(
@@ -1028,15 +1002,10 @@ def create_interface():
1028
  outputs=[dna_input, fasta_file, similarity_score, build_ml_tree, status_display]
1029
  )
1030
 
1031
- view_tree_btn.click(
1032
- fn=view_tree,
1033
  inputs=[html_file],
1034
- outputs=[tree_modal, tree_modal, close_btn]
1035
- )
1036
-
1037
- close_btn.click(
1038
- fn=close_modal,
1039
- outputs=[tree_modal, close_btn]
1040
  )
1041
 
1042
  # Example data loading
 
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"""
 
747
  height: 600px !important;
748
  overflow: auto;
749
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
750
  """
751
 
752
  with gr.Blocks(css=custom_css, title="F Gene Analysis Pipeline") as iface:
 
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
 
873
  # File downloads
874
  gr.Markdown("### 📁 Download Results")
 
977
  def clear_inputs():
978
  return "", None, 95.0, False, "Ready to analyze"
979
 
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(
 
1002
  outputs=[dna_input, fasta_file, similarity_score, build_ml_tree, status_display]
1003
  )
1004
 
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