re-type commited on
Commit
2085fa2
·
verified ·
1 Parent(s): 94cbce7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -977,19 +977,11 @@ def create_interface():
977
  def open_tree(html_file):
978
  if html_file and os.path.exists(html_file):
979
  try:
980
- # Generate a temporary URL for the file using Gradio's file serving in a Space
981
- from gradio.utils import get_space
982
- space_url = get_space() # Gets the Space URL if running in a Space
983
- if space_url:
984
- # Construct a URL to the file (relative path from the Space root)
985
- file_path = os.path.relpath(html_file, os.getcwd())
986
- file_url = f"{space_url}/file={file_path}"
987
- return gr.update(value=f"<script>window.open('{file_url}', '_blank');</script>")
988
- else:
989
- # Fallback for local testing or if space_url fails
990
- 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>")
991
  except Exception as e:
992
- 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>")
993
  return gr.update(value="<p>No tree file available. Run analysis to generate one.</p>")
994
 
995
  # Connect events
 
977
  def open_tree(html_file):
978
  if html_file and os.path.exists(html_file):
979
  try:
980
+ # Use Gradio's file serving by providing the file path directly
981
+ file_url = f"/file={html_file}"
982
+ return gr.update(value=f"<script>window.open('{file_url}', '_blank');</script>")
 
 
 
 
 
 
 
 
983
  except Exception as e:
984
+ return gr.update(value=f"<p>Error opening tree: {str(e)}. Please download the file and open it manually: <a href='/file={html_file}' download>Download</a></p>")
985
  return gr.update(value="<p>No tree file available. Run analysis to generate one.</p>")
986
 
987
  # Connect events