Skip to content
Snippets Groups Projects

Updated File explorer to work with large data directories

1 file
+ 19
35
Compare changes
  • Side-by-side
  • Inline
+ 19
35
@@ -56,28 +56,17 @@ class Interface:
"""Used to reset outputs with the clear button"""
return None
def update_directory(self, new_path):
""" Updates the current directory for ui components
Args:
new_path (str): path to the new directory
Raises:
ValueError: In case the path is invalid
Returns:
gr.Update: Returns a gr.Update object for both explorer and base_path components
"""
def update_explorer(self, new_path):
new_path = os.path.expanduser(new_path)
# In case we have a directory
if os.path.isdir(new_path):
return gr.update(root_dir=new_path, label=new_path), gr.update(value=new_path, choices=[os.path.join(new_path, folder) for folder in os.listdir(new_path) if os.path.isdir(os.path.join(new_path, folder))])
return gr.update(root_dir=new_path, label=new_path)
elif os.path.isfile(new_path):
parent_dir = os.path.dirname(new_path)
file_name = str(os.path.basename(new_path))
return gr.update(root_dir=parent_dir, label=parent_dir, value=file_name), gr.update(value=parent_dir, choices=[os.path.join(parent_dir, folder) for folder in os.listdir(parent_dir) if os.path.isdir(os.path.join(parent_dir, folder))])
return gr.update(root_dir=parent_dir, label=parent_dir, value=file_name)
else:
raise ValueError("Invalid path")
@@ -118,23 +107,19 @@ class Interface:
gr.Markdown("### File selection")
with gr.Row():
with gr.Column(scale=99, min_width=128):
base_path = gr.Dropdown(
base_path = gr.Textbox(
max_lines=1,
container=False,
label="Base path",
elem_classes="h-36",
value=os.getcwd(),
choices=[os.path.join(os.getcwd(), folder) for folder in os.listdir(os.getcwd()) if os.path.isdir(os.path.join(os.getcwd(), folder))],
interactive=True,
allow_custom_value=True,
)
with gr.Column(scale=1, min_width=36):
reload_base_path = gr.Button(
value="", elem_classes="btn-html h-36"
)
explorer = gr.FileExplorer(
#glob=".*",
#ignore_glob="*/",
ignore_glob="*/.*", # ignores hidden files
root_dir=os.getcwd(),
label=os.getcwd(),
render=True,
@@ -174,6 +159,7 @@ class Interface:
# Visualization and results
with gr.Row(elem_classes="mt-64"):
# Z Slicer
with gr.Column(visible=False) as result_z_slicer:
zslice_plot = gr.Plot(label="Z slice", elem_classes="rounded")
@@ -211,7 +197,7 @@ class Interface:
# Intensity histogram
with gr.Column(visible=False) as result_intensity_histogram:
hist_plot = gr.Plot(label="Volume intensity histogram")
# Text box with data summary
with gr.Column(visible=False) as result_data_summary:
data_summary = gr.Text(
@@ -257,6 +243,7 @@ class Interface:
min_projection_plot,
hist_plot,
data_summary,
]
### Listeners
@@ -264,8 +251,8 @@ class Interface:
spinner_loading = gr.Text("Loading data...", visible=False)
spinner_operations = gr.Text("Running pipeline...", visible=False)
# fmt: off
reload_base_path.click(fn=self.update_directory,inputs=base_path, outputs=[explorer, base_path])
reload_base_path.click(fn=self.update_explorer,inputs=base_path, outputs=explorer)
btn_run.click(
fn=self.set_spinner, inputs=spinner_session, outputs=btn_run).then(
fn=self.start_session, inputs=inputs, outputs=session).then(
@@ -284,7 +271,7 @@ class Interface:
ypos.change(
fn=self.update_ypos, inputs=[session, ypos], outputs=[session, yslice_plot]).success(
fn=pipeline.create_yslice_fig, inputs=[], outputs=yslice_plot,show_progress="hidden")
xpos.change(
fn=self.update_xpos, inputs=[session, xpos], outputs=[session, xslice_plot]).success(
fn=pipeline.create_xslice_fig, inputs=[], outputs=xslice_plot,show_progress="hidden")
@@ -621,15 +608,13 @@ class Pipeline:
return max_projection, min_projection
def plot_vol_histogram(self):
# The Histogram needs results from the projections
# The Histogram needs results from the projections
if not self.session.projections_calculated:
_ = self.get_projections(self.session.vol)
vol_hist, bin_edges = self.vol_histogram(
self.session.vol,
self.session.nbins,
self.session.min_value,
self.session.max_value,
self.session.vol, self.session.nbins, self.session.min_value, self.session.max_value
)
fig, ax = plt.subplots(figsize=(6, 4))
@@ -662,12 +647,11 @@ class Pipeline:
return vol_hist, bin_edges
def run_interface(host="0.0.0.0"):
def run_interface(host = "0.0.0.0"):
gradio_interface = Interface().create_interface()
internal_tools.run_gradio_app(gradio_interface, host)
internal_tools.run_gradio_app(gradio_interface,host)
if __name__ == "__main__":
# Creates interface
run_interface()
run_interface()
\ No newline at end of file
Loading