Updated app code to work with new Gradio version
Browse files- demo/src/gui.py +22 -40
demo/src/gui.py
CHANGED
@@ -2,6 +2,8 @@ import os
|
|
2 |
|
3 |
import gradio as gr
|
4 |
|
|
|
|
|
5 |
from .convert import nifti_to_obj
|
6 |
from .css_style import css
|
7 |
from .inference import run_model
|
@@ -50,14 +52,8 @@ class WebUI:
|
|
50 |
step=1,
|
51 |
label="Which 2D slice to show",
|
52 |
)
|
53 |
-
self.volume_renderer = gr.Model3D(
|
54 |
-
|
55 |
-
label="3D Model",
|
56 |
-
show_label=True,
|
57 |
-
visible=True,
|
58 |
-
elem_id="model-3d",
|
59 |
-
camera_position=[90, 180, 768],
|
60 |
-
).style(height=512)
|
61 |
|
62 |
def set_class_name(self, value):
|
63 |
LOGGER.info(f"Changed task to: {value}")
|
@@ -92,11 +88,7 @@ class WebUI:
|
|
92 |
|
93 |
def get_img_pred_pair(self, k):
|
94 |
k = int(k)
|
95 |
-
out = gr.AnnotatedImage(self.combine_ct_and_seg(self.images[k], self.pred_images[k]), visible=True, elem_id="model-2d",)
|
96 |
-
color_map={self.class_name: "#ffae00"},
|
97 |
-
height=512,
|
98 |
-
width=512,
|
99 |
-
)
|
100 |
return out
|
101 |
|
102 |
def toggle_sidebar(self, state):
|
@@ -116,9 +108,9 @@ class WebUI:
|
|
116 |
autoscroll=True,
|
117 |
elem_id="logs",
|
118 |
show_copy_button=True,
|
119 |
-
scroll_to_output=False,
|
120 |
container=True,
|
121 |
-
line_breaks=True,
|
122 |
)
|
123 |
demo.load(read_logs, None, logs, every=1)
|
124 |
|
@@ -148,7 +140,6 @@ class WebUI:
|
|
148 |
label="Task",
|
149 |
info="Which structure to segment.",
|
150 |
multiselect=False,
|
151 |
-
size="sm",
|
152 |
)
|
153 |
model_selector.input(
|
154 |
fn=lambda x: self.set_class_name(x),
|
@@ -157,10 +148,7 @@ class WebUI:
|
|
157 |
)
|
158 |
|
159 |
with gr.Column(scale=0.2, min_width=150):
|
160 |
-
run_btn = gr.Button("Run analysis", variant="primary", elem_id="run-button"
|
161 |
-
full_width=False,
|
162 |
-
size="lg",
|
163 |
-
)
|
164 |
run_btn.click(
|
165 |
fn=lambda x: self.process(x),
|
166 |
inputs=file_output,
|
@@ -175,7 +163,7 @@ class WebUI:
|
|
175 |
inputs=file_output,
|
176 |
outputs=file_output,
|
177 |
fn=self.upload_file,
|
178 |
-
cache_examples=
|
179 |
)
|
180 |
|
181 |
gr.Markdown(
|
@@ -186,25 +174,19 @@ class WebUI:
|
|
186 |
)
|
187 |
|
188 |
with gr.Row():
|
189 |
-
with gr.
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
)
|
203 |
-
|
204 |
-
self.slider.render()
|
205 |
-
|
206 |
-
with gr.Box():
|
207 |
-
self.volume_renderer.render()
|
208 |
|
209 |
# sharing app publicly -> share=True:
|
210 |
# https://gradio.app/sharing-your-app/
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
|
5 |
+
from gradio_shinymodel3d import ShinyModel3D
|
6 |
+
|
7 |
from .convert import nifti_to_obj
|
8 |
from .css_style import css
|
9 |
from .inference import run_model
|
|
|
52 |
step=1,
|
53 |
label="Which 2D slice to show",
|
54 |
)
|
55 |
+
#self.volume_renderer = gr.Model3D(
|
56 |
+
self.volume_renderer = ShinyModel3D()
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
def set_class_name(self, value):
|
59 |
LOGGER.info(f"Changed task to: {value}")
|
|
|
88 |
|
89 |
def get_img_pred_pair(self, k):
|
90 |
k = int(k)
|
91 |
+
out = gr.AnnotatedImage(self.combine_ct_and_seg(self.images[k], self.pred_images[k]), visible=True, elem_id="model-2d",)
|
|
|
|
|
|
|
|
|
92 |
return out
|
93 |
|
94 |
def toggle_sidebar(self, state):
|
|
|
108 |
autoscroll=True,
|
109 |
elem_id="logs",
|
110 |
show_copy_button=True,
|
111 |
+
#scroll_to_output=False,
|
112 |
container=True,
|
113 |
+
#line_breaks=True,
|
114 |
)
|
115 |
demo.load(read_logs, None, logs, every=1)
|
116 |
|
|
|
140 |
label="Task",
|
141 |
info="Which structure to segment.",
|
142 |
multiselect=False,
|
|
|
143 |
)
|
144 |
model_selector.input(
|
145 |
fn=lambda x: self.set_class_name(x),
|
|
|
148 |
)
|
149 |
|
150 |
with gr.Column(scale=0.2, min_width=150):
|
151 |
+
run_btn = gr.Button("Run analysis", variant="primary", elem_id="run-button")
|
|
|
|
|
|
|
152 |
run_btn.click(
|
153 |
fn=lambda x: self.process(x),
|
154 |
inputs=file_output,
|
|
|
163 |
inputs=file_output,
|
164 |
outputs=file_output,
|
165 |
fn=self.upload_file,
|
166 |
+
cache_examples=False,
|
167 |
)
|
168 |
|
169 |
gr.Markdown(
|
|
|
174 |
)
|
175 |
|
176 |
with gr.Row():
|
177 |
+
with gr.Column():
|
178 |
+
# create dummy image to be replaced by loaded images
|
179 |
+
t = gr.AnnotatedImage(visible=True, elem_id="model-2d")
|
180 |
+
|
181 |
+
self.slider.input(
|
182 |
+
self.get_img_pred_pair,
|
183 |
+
self.slider,
|
184 |
+
t,
|
185 |
+
)
|
186 |
+
|
187 |
+
self.slider.render()
|
188 |
+
|
189 |
+
self.volume_renderer.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
|
191 |
# sharing app publicly -> share=True:
|
192 |
# https://gradio.app/sharing-your-app/
|