Skip to content

Commit

Permalink
Merge main to release
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 16, 2024
2 parents edea3f8 + dfa9a85 commit e32828d
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 166 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = [
"nrtk",
"numpy",
"Pillow",
"scikit-learn==1.4.1.post1",
"scikit-learn==1.4.2",
"smqtk-classifier==0.19.0",
"accelerate",
"smqtk-core==0.19.0",
Expand All @@ -47,7 +47,7 @@ dependencies = [
"trame-client>=2.15.0",
"trame-quasar",
"trame-server>=2.15.0",
"ubelt==1.3.4",
"ubelt==1.3.5",
"umap-learn",
"tabulate",
]
Expand Down
178 changes: 18 additions & 160 deletions src/nrtk_explorer/app/core.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
r"""
Define your classes and create the instances that you need to expose
"""

import logging
from typing import Iterable

from trame.ui.quasar import QLayout
from trame.widgets import quasar
from trame.widgets import html
from trame_server.utils.namespace import Translator
from nrtk_explorer.library import images_manager
Expand All @@ -16,7 +10,7 @@
from nrtk_explorer.app.transforms import TransformsApp
from nrtk_explorer.app.filtering import FilteringApp
from nrtk_explorer.app.applet import Applet
from nrtk_explorer.app.ui.collapsible_card import collapsible_card
from nrtk_explorer.app import ui
import nrtk_explorer.test_data
from pathlib import Path

Expand Down Expand Up @@ -49,10 +43,6 @@ def image_id_to_result(image_id):
return f"{image_id}_result"


def parse_dataset_dirs(datasets):
return [{"label": Path(ds).name, "value": ds} for ds in datasets]


# ---------------------------------------------------------
# Engine class
# ---------------------------------------------------------
Expand All @@ -77,8 +67,6 @@ def __init__(self, server=None):
self.context["images_manager"] = images_manager.ImagesManager()
self.context["annotations"] = {}

self._ui = None

self.state.collapse_dataset = False
self.state.collapse_embeddings = False
self.state.collapse_filter = False
Expand Down Expand Up @@ -125,7 +113,7 @@ def __init__(self, server=None):
self.state.trame__title = "nrtk_explorer"

# Bind instance methods to controller
self.ctrl.on_server_reload = self.ui
self.ctrl.on_server_reload = self._build_ui
self.ctrl.add("on_server_ready")(self.on_server_ready)

self.state.num_images_max = 0
Expand All @@ -134,8 +122,8 @@ def __init__(self, server=None):
self.state.random_sampling_disabled = True
self.state.images_id = []

# Generate UI
self.ui()
self._build_ui()

self.context.images_manager = images_manager.ImagesManager()

def on_server_ready(self, *args, **kwargs):
Expand Down Expand Up @@ -213,147 +201,17 @@ def reload_images(self):
self.state.annotation_categories = categories
self.state.images_ids = [img["id"] for img in selected_images]

def ui(self, *args, **kwargs):
if self._ui is None:
with QLayout(
self.server, view="lhh LpR lff", classes="shadow-2 rounded-borders bg-grey-2"
) as layout:
# # Toolbar
with quasar.QHeader():
with quasar.QToolbar(classes="shadow-4"):
quasar.QToolbarTitle("NRTK_EXPLORER")

# # Main content
with quasar.QPageContainer():
with quasar.QPage():
with quasar.QSplitter(
model_value=("horizontal_split",),
classes="inherit-height",
before_class="inherit-height zero-height scroll",
after_class="inherit-height zero-height",
):
with html.Template(v_slot_before=True):
with html.Div(classes="q-pa-md q-gutter-md"):
(
dataset_title_slot,
dataset_content_slot,
dataset_actions_slot,
) = collapsible_card("collapse_dataset")

with dataset_title_slot:
html.Span("Dataset Selection", classes="text-h6")

with dataset_content_slot:
quasar.QSelect(
label="Dataset",
v_model=("current_dataset",),
options=(parse_dataset_dirs(self.input_paths),),
filled=True,
emit_value=True,
map_options=True,
dense=True,
)
quasar.QSlider(
v_model=("num_images", 15),
min=(0,),
max=("num_images_max", 25),
disable=("num_images_disabled", True),
step=(1,),
)
html.P(
"{{num_images}}/{{num_images_max}} images",
classes="text-caption text-center",
)

quasar.QToggle(
v_model=("random_sampling", False),
dense=False,
label="Random selection",
)

(
embeddings_title_slot,
embeddings_content_slot,
embeddings_actions_slot,
) = collapsible_card("collapse_embeddings")

with embeddings_title_slot:
html.Span("Embeddings", classes="text-h6")

with embeddings_content_slot:
self._embeddings_app.settings_widget()

with embeddings_actions_slot:
self._embeddings_app.compute_ui()

filter_title_slot, filter_content_slot, filter_actions_slot = (
collapsible_card("collapse_filter")
)

with filter_title_slot:
html.Span("Category Filter", classes="text-h6")

with filter_content_slot:
self._filtering_app.filter_operator_ui()
self._filtering_app.filter_options_ui()

with filter_actions_slot:
self._filtering_app.filter_apply_ui()

(
transforms_title_slot,
transforms_content_slot,
transforms_actions_slot,
) = collapsible_card("collapse_transforms")

with transforms_title_slot:
html.Span("Transform Settings", classes="text-h6")

with transforms_content_slot:
self._transforms_app.settings_widget()

with transforms_actions_slot:
self._transforms_app.apply_ui()

with html.Template(v_slot_after=True):
with quasar.QSplitter(
v_model=("vertical_split",),
limits=("[0,100]",),
horizontal=True,
classes="inherit-height zero-height",
before_class="q-pa-md",
after_class="q-pa-md",
):
with html.Template(v_slot_before=True):
self._embeddings_app.visualization_widget()

with html.Template(v_slot_after=True):
with html.Div(classes="row q-col-gutter-md"):
with html.Div(classes="col-6"):
with quasar.QCard(flat=True, bordered=True):
with quasar.QCardSection():
html.Span(
"Original Dataset", classes="text-h5"
)

with quasar.QCardSection():
self._transforms_app.original_dataset_widget()

with html.Div(classes="col-6"):
with quasar.QCard(
flat=True,
bordered=True,
style="background-color: #ffcdd2;",
):
with quasar.QCardSection():
html.Span(
"Transformed Dataset",
classes="text-h5",
)

with quasar.QCardSection():
self._transforms_app.transformed_dataset_widget()

self._ui = layout

return self._ui
def _build_ui(self):
extra_args = {}
if self.server.hot_reload:
ui.reload(ui)
extra_args["reload"] = self._build_ui

self.ui = ui.build_layout(
server=self.server,
dataset_paths=self.input_paths,
embeddings_app=self._embeddings_app,
filtering_app=self._filtering_app,
transforms_app=self._transforms_app,
**extra_args,
)
6 changes: 3 additions & 3 deletions src/nrtk_explorer/app/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import nrtk_explorer.library.transforms as trans
import nrtk_explorer.library.nrtk_transforms as nrtk_trans
from nrtk_explorer.library import images_manager, object_detector
from nrtk_explorer.app.ui.image_list import image_list_component
from nrtk_explorer.app import ui
from nrtk_explorer.app.applet import Applet
from nrtk_explorer.app.parameters import ParametersApp
from nrtk_explorer.library.ml_models import (
Expand Down Expand Up @@ -350,11 +350,11 @@ def apply_ui(self):

def original_dataset_widget(self):
with html.Div(trame_server=self.server):
image_list_component("source_image_ids", self.on_hover)
ui.image_list_component("source_image_ids", self.on_hover)

def transformed_dataset_widget(self):
with html.Div(trame_server=self.server):
image_list_component("transformed_image_ids", self.on_hover, is_transformation=True)
ui.image_list_component("transformed_image_ids", self.on_hover, is_transformation=True)

# This is only used within when this module (file) is executed as an Standalone app.
@property
Expand Down
20 changes: 20 additions & 0 deletions src/nrtk_explorer/app/ui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from .layout import build_layout
from .image_list import image_list_component
from .collapsible_card import card


def reload(m=None):
from . import collapsible_card, image_list, layout

collapsible_card.__loader__.exec_module(collapsible_card)
image_list.__loader__.exec_module(image_list)
layout.__loader__.exec_module(layout)
if m:
m.__loader__.exec_module(m)


__all__ = [
"build_layout",
"image_list_component",
"card",
]
2 changes: 1 addition & 1 deletion src/nrtk_explorer/app/ui/collapsible_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from trame.widgets import html


def collapsible_card(collapse_key):
def card(collapse_key):
with quasar.QCard():
with quasar.QCardSection():
with html.Div(classes="row items-center no-wrap"):
Expand Down
Loading

0 comments on commit e32828d

Please sign in to comment.