Merge pull request #31 from andreped/hf-demo
Browse filesFixed image viewer alignment and file upload; removed HU clip
- demo/src/gui.py +50 -46
- demo/src/utils.py +2 -2
demo/src/gui.py
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
import os
|
2 |
|
3 |
import gradio as gr
|
|
|
4 |
|
5 |
from .compute import run_model
|
6 |
from .utils import load_ct_to_numpy
|
7 |
-
from .utils import load_pred_volume_to_numpy
|
8 |
-
from .utils import nifti_to_glb
|
9 |
|
10 |
|
11 |
class WebUI:
|
@@ -41,24 +40,28 @@ class WebUI:
|
|
41 |
label="Which 2D slice to show",
|
42 |
)
|
43 |
|
|
|
|
|
|
|
|
|
44 |
def set_class_name(self, value):
|
45 |
print("Changed task to:", value)
|
46 |
self.class_name = value
|
47 |
|
48 |
def upload_file(self, files):
|
49 |
-
return files
|
50 |
|
51 |
def process(self, mesh_file_names):
|
52 |
fixed_image_path = mesh_file_names[0].name
|
53 |
moving_image_path = mesh_file_names[1].name
|
|
|
54 |
|
55 |
-
run_model(
|
56 |
|
57 |
self.fixed_images = load_ct_to_numpy(fixed_image_path)
|
58 |
self.moving_images = load_ct_to_numpy(moving_image_path)
|
59 |
-
|
60 |
-
self.pred_images
|
61 |
-
return None
|
62 |
|
63 |
def get_fixed_image(self, k):
|
64 |
k = int(k) - 1
|
@@ -123,14 +126,7 @@ class WebUI:
|
|
123 |
outputs=None,
|
124 |
)
|
125 |
|
126 |
-
run_btn
|
127 |
-
full_width=False, size="lg"
|
128 |
-
)
|
129 |
-
run_btn.click(
|
130 |
-
fn=lambda x: self.process(x),
|
131 |
-
inputs=file_output,
|
132 |
-
outputs=None,
|
133 |
-
)
|
134 |
|
135 |
"""
|
136 |
with gr.Row():
|
@@ -149,38 +145,46 @@ class WebUI:
|
|
149 |
with gr.Row():
|
150 |
with gr.Box():
|
151 |
with gr.Column():
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
)
|
183 |
-
pred_images.append(t)
|
184 |
|
185 |
self.slider.input(
|
186 |
self.get_fixed_image, self.slider, fixed_images
|
|
|
1 |
import os
|
2 |
|
3 |
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
|
6 |
from .compute import run_model
|
7 |
from .utils import load_ct_to_numpy
|
|
|
|
|
8 |
|
9 |
|
10 |
class WebUI:
|
|
|
40 |
label="Which 2D slice to show",
|
41 |
)
|
42 |
|
43 |
+
self.run_btn = gr.Button("Run analysis").style(
|
44 |
+
full_width=False, size="lg"
|
45 |
+
)
|
46 |
+
|
47 |
def set_class_name(self, value):
|
48 |
print("Changed task to:", value)
|
49 |
self.class_name = value
|
50 |
|
51 |
def upload_file(self, files):
|
52 |
+
return [f.name for f in files]
|
53 |
|
54 |
def process(self, mesh_file_names):
|
55 |
fixed_image_path = mesh_file_names[0].name
|
56 |
moving_image_path = mesh_file_names[1].name
|
57 |
+
output_path = "./"
|
58 |
|
59 |
+
run_model(fixed_image_path, moving_image_path, output_path, self.class_names[self.class_name])
|
60 |
|
61 |
self.fixed_images = load_ct_to_numpy(fixed_image_path)
|
62 |
self.moving_images = load_ct_to_numpy(moving_image_path)
|
63 |
+
self.pred_images = np.ones_like(self.moving_images)
|
64 |
+
return self.pred_images
|
|
|
65 |
|
66 |
def get_fixed_image(self, k):
|
67 |
k = int(k) - 1
|
|
|
126 |
outputs=None,
|
127 |
)
|
128 |
|
129 |
+
self.run_btn.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
"""
|
132 |
with gr.Row():
|
|
|
145 |
with gr.Row():
|
146 |
with gr.Box():
|
147 |
with gr.Column():
|
148 |
+
|
149 |
+
with gr.Row():
|
150 |
+
fixed_images = []
|
151 |
+
for i in range(self.nb_slider_items):
|
152 |
+
visibility = True if i == 1 else False
|
153 |
+
t = gr.Image(
|
154 |
+
visible=visibility, elem_id="model-2d-fixed"
|
155 |
+
).style(
|
156 |
+
height=512,
|
157 |
+
width=512,
|
158 |
+
)
|
159 |
+
fixed_images.append(t)
|
160 |
+
|
161 |
+
moving_images = []
|
162 |
+
for i in range(self.nb_slider_items):
|
163 |
+
visibility = True if i == 1 else False
|
164 |
+
t = gr.Image(
|
165 |
+
visible=visibility, elem_id="model-2d-moving"
|
166 |
+
).style(
|
167 |
+
height=512,
|
168 |
+
width=512,
|
169 |
+
)
|
170 |
+
moving_images.append(t)
|
171 |
+
|
172 |
+
pred_images = []
|
173 |
+
for i in range(self.nb_slider_items):
|
174 |
+
visibility = True if i == 1 else False
|
175 |
+
t = gr.Image(
|
176 |
+
visible=visibility, elem_id="model-2d-pred"
|
177 |
+
).style(
|
178 |
+
height=512,
|
179 |
+
width=512,
|
180 |
+
)
|
181 |
+
pred_images.append(t)
|
182 |
+
|
183 |
+
self.run_btn.click(
|
184 |
+
fn=lambda x: self.process(x),
|
185 |
+
inputs=file_output,
|
186 |
+
outputs=t,
|
187 |
)
|
|
|
188 |
|
189 |
self.slider.input(
|
190 |
self.get_fixed_image, self.slider, fixed_images
|
demo/src/utils.py
CHANGED
@@ -14,8 +14,8 @@ def load_ct_to_numpy(data_path):
|
|
14 |
|
15 |
data = np.rot90(data, k=1, axes=(0, 1))
|
16 |
|
17 |
-
data[data < -150] = -150
|
18 |
-
data[data > 250] = 250
|
19 |
|
20 |
data = data - np.amin(data)
|
21 |
data = data / np.amax(data) * 255
|
|
|
14 |
|
15 |
data = np.rot90(data, k=1, axes=(0, 1))
|
16 |
|
17 |
+
#data[data < -150] = -150
|
18 |
+
#data[data > 250] = 250
|
19 |
|
20 |
data = data - np.amin(data)
|
21 |
data = data / np.amax(data) * 255
|