Bearr commited on
Commit
8ed3c78
·
verified ·
1 Parent(s): e128a13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import gradio as gr
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
  import plotly.graph_objects as go
@@ -7,7 +7,7 @@ from skimage import measure
7
  from mpl_toolkits.mplot3d.art3d import Poly3DCollection
8
  from lungmask import LMInferer
9
  import SimpleITK as sitk
10
- import os
11
 
12
  # --- Lung Segmentation Functions ---
13
 
@@ -56,15 +56,21 @@ def plot_3d_lungs(lungs_volume, threshold=0.5):
56
  fig.update_layout(scene_aspectmode='data') # Maintain aspect ratio
57
  return fig
58
 
 
59
 
 
 
 
60
 
61
- # --- Create Gradio Interface ---
 
 
62
 
63
- inputs = gr.Textbox(label="DICOM Folder Path")
64
  output = gr.Plot(label="3D Segmented Lungs")
65
 
66
  iface = gr.Interface(
67
- fn=lambda dcm_folder: plot_3d_lungs(segment_lungs_from_dicom(dcm_folder)),
68
  inputs=inputs,
69
  outputs=output,
70
  title="3D Lung Segmentation Visualization",
 
1
+ import os
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
  import plotly.graph_objects as go
 
7
  from mpl_toolkits.mplot3d.art3d import Poly3DCollection
8
  from lungmask import LMInferer
9
  import SimpleITK as sitk
10
+ import gradio as gr
11
 
12
  # --- Lung Segmentation Functions ---
13
 
 
56
  fig.update_layout(scene_aspectmode='data') # Maintain aspect ratio
57
  return fig
58
 
59
+ # --- Gradio Interface ---
60
 
61
+ def process_and_visualize(selected_folder):
62
+ if selected_folder not in ["tumor", "lungs"]:
63
+ return "Invalid folder selection." # Handle invalid input
64
 
65
+ volume = segment_lungs_from_dicom(selected_folder)
66
+ visualization = plot_3d_lungs(volume)
67
+ return visualization
68
 
69
+ inputs = gr.Dropdown(choices=["tumor", "lungs"], label="Select DICOM Folder")
70
  output = gr.Plot(label="3D Segmented Lungs")
71
 
72
  iface = gr.Interface(
73
+ fn=process_and_visualize,
74
  inputs=inputs,
75
  outputs=output,
76
  title="3D Lung Segmentation Visualization",