Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions plugins/operator-examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,22 @@ def execute(self, ctx):
print(f"Message: {ctx.params['message']}")


class SetSampleModal(foo.Operator):
@property
def config(self):
return foo.OperatorConfig(
name="set_sample_modal",
label="Set sample modal",
)

def execute(self, ctx):
cur_sample = ctx.dataset[ctx.current_sample]
cur_sample.heatmaps.map_path = cur_sample.heatmaps.alt_path
ctx.ops.update_app_samples(
[dict(id=cur_sample.id, values=cur_sample.to_dict())]
)


def register(p):
p.register(MessagesExample)
p.register(SimpleInputExample)
Expand All @@ -909,3 +925,4 @@ def register(p):
p.register(TargetViewExample)
p.register(PythonViewExample)
p.register(ExampleComplexExecution)
p.register(SetSampleModal)
1 change: 1 addition & 0 deletions plugins/operator-examples/fiftyone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ operators:
- example_lazy_field
- example_python_view
- example_complex_execution
- set_sample_modal
secrets:
- FIFTYONE_EXAMPLE_SECRET
49 changes: 49 additions & 0 deletions plugins/panel-examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,54 @@ def render(self, ctx):
)


import fiftyone as fo
import random as rand


def gen_random_bbox():
min_x = rand.randint(0, 100) / 100
min_y = rand.randint(0, 100) / 100
max_x = min_x + rand.randint(1, 10) / 100
max_y = min_y + rand.randint(1, 10) / 100
return [min_x, min_y, max_x, max_y]


class UpdateModalExample(foo.Panel):
@property
def config(self):
return foo.PanelConfig(
name="example_update_modal",
label="Examples: Update Modal",
surfaces="modal",
)

def on_click(self, ctx):
cur_sample = ctx.dataset[ctx.current_sample]
cur_sample.ground_truth.detections.clear()
cur_sample.ground_truth.detections.append(
fo.Detection(label="person", bounding_box=gen_random_bbox())
)
ctx.ops.set_active_fields(["ground_truth"])
if ctx.panel.state.save:
cur_sample.save()
ctx.ops.reload_current_sample()
else:
ctx.ops.update_app_samples(
[dict(id=cur_sample.id, values=cur_sample.to_dict())]
)

def render(self, ctx):
panel = types.Object()
panel.bool("save", label="Save changes?", default=False)
panel.btn("btn", label="Add random bbox", on_click=self.on_click)
return types.Property(
panel,
# view=types.GridView(
# height=100, width=100, align_x="center", align_y="center"
# ),
)


def register(p):
p.register(CounterExample)
p.register(PlotExample)
Expand All @@ -794,3 +842,4 @@ def register(p):
p.register(InteractivePlotExample)
p.register(DropdownMenuExample)
p.register(WalkthroughExample)
p.register(UpdateModalExample)
1 change: 1 addition & 0 deletions plugins/panel-examples/fiftyone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ panels:
- example_interactive_plot
- example_dropdown_menu
- example_walkthrough
- example_update_modal