Skip to content

Commit

Permalink
Merge pull request #9 from andreped/ShinyModel3D
Browse files Browse the repository at this point in the history
Enhanced Model3D viewer; upgraded gradio to latest release v4.3.0
  • Loading branch information
andreped authored Nov 14, 2023
2 parents a8b54e4 + 0dcf10b commit 1d8ac2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 41 deletions.
3 changes: 2 additions & 1 deletion demo/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
raidionicsrads@git+https://github.com/dbouget/raidionics_rads_lib
gradio==3.50.2
gradio==4.3.0
gradio_shinymodel3d@https://github.com/raidionics/LyNoS/releases/download/ShinyModel3D/gradio_shinymodel3d-0.0.1-py3-none-any.whl
62 changes: 22 additions & 40 deletions demo/src/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import gradio as gr

from gradio_shinymodel3d import ShinyModel3D

from .convert import nifti_to_obj
from .css_style import css
from .inference import run_model
Expand Down Expand Up @@ -50,14 +52,8 @@ def __init__(
step=1,
label="Which 2D slice to show",
)
self.volume_renderer = gr.Model3D(
clear_color=[0.0, 0.0, 0.0, 0.0],
label="3D Model",
show_label=True,
visible=True,
elem_id="model-3d",
camera_position=[90, 180, 768],
).style(height=512)
#self.volume_renderer = gr.Model3D(
self.volume_renderer = ShinyModel3D()

def set_class_name(self, value):
LOGGER.info(f"Changed task to: {value}")
Expand Down Expand Up @@ -92,11 +88,7 @@ def process(self, mesh_file_name):

def get_img_pred_pair(self, k):
k = int(k)
out = gr.AnnotatedImage(self.combine_ct_and_seg(self.images[k], self.pred_images[k]), visible=True, elem_id="model-2d",).style(
color_map={self.class_name: "#ffae00"},
height=512,
width=512,
)
out = gr.AnnotatedImage(self.combine_ct_and_seg(self.images[k], self.pred_images[k]), visible=True, elem_id="model-2d",)
return out

def toggle_sidebar(self, state):
Expand All @@ -116,9 +108,9 @@ def run(self):
autoscroll=True,
elem_id="logs",
show_copy_button=True,
scroll_to_output=False,
#scroll_to_output=False,
container=True,
line_breaks=True,
#line_breaks=True,
)
demo.load(read_logs, None, logs, every=1)

Expand Down Expand Up @@ -148,7 +140,6 @@ def run(self):
label="Task",
info="Which structure to segment.",
multiselect=False,
size="sm",
)
model_selector.input(
fn=lambda x: self.set_class_name(x),
Expand All @@ -157,10 +148,7 @@ def run(self):
)

with gr.Column(scale=0.2, min_width=150):
run_btn = gr.Button("Run analysis", variant="primary", elem_id="run-button",).style(
full_width=False,
size="lg",
)
run_btn = gr.Button("Run analysis", variant="primary", elem_id="run-button")
run_btn.click(
fn=lambda x: self.process(x),
inputs=file_output,
Expand All @@ -175,7 +163,7 @@ def run(self):
inputs=file_output,
outputs=file_output,
fn=self.upload_file,
cache_examples=True,
cache_examples=False,
)

gr.Markdown(
Expand All @@ -186,25 +174,19 @@ def run(self):
)

with gr.Row():
with gr.Box():
with gr.Column():
# create dummy image to be replaced by loaded images
t = gr.AnnotatedImage(visible=True, elem_id="model-2d").style(
color_map={self.class_name: "#ffae00"},
height=512,
width=512,
)

self.slider.input(
self.get_img_pred_pair,
self.slider,
t,
)

self.slider.render()

with gr.Box():
self.volume_renderer.render()
with gr.Column():
# create dummy image to be replaced by loaded images
t = gr.AnnotatedImage(visible=True, elem_id="model-2d")

self.slider.input(
self.get_img_pred_pair,
self.slider,
t,
)

self.slider.render()

self.volume_renderer.render()

# sharing app publicly -> share=True:
# https://gradio.app/sharing-your-app/
Expand Down

0 comments on commit 1d8ac2e

Please sign in to comment.