Skip to content

Commit 62d9a65

Browse files
committed
resolve todo
1 parent d654bf1 commit 62d9a65

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

plugins/operator-examples/__init__.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -889,14 +889,23 @@ def config(self):
889889

890890
def resolve_input(self, ctx):
891891
inputs = types.Object()
892-
inputs.message(
893-
"Sample Download",
894-
label="Select a sample to download its image",
895-
description="This operator allows you to select a sample and download its image file.",
892+
893+
inputs.md(
894+
"This operator allows you to download a sample's source media"
896895
)
896+
897+
if ctx.current_sample is not None:
898+
label = "Press `Execute` to download the current sample's media"
899+
else:
900+
label = "Please open a sample in the modal first"
901+
902+
inputs.message("Sample Download", label=label)
897903
return types.Property(inputs)
898904

899905
def execute(self, ctx):
906+
import os
907+
import fiftyone.core.storage as fos
908+
900909
if ctx.current_sample is None:
901910
raise ValueError(
902911
"No sample selected. Please select a sample first."
@@ -905,14 +914,10 @@ def execute(self, ctx):
905914
sample = ctx.dataset[ctx.current_sample]
906915
filepath = sample.filepath
907916

908-
# Create download URL for the media file
909-
import fiftyone.core.storage as fos
910-
911-
# TODO make this work in teams
912-
download_url = f"http://localhost:5151/media?filepath={filepath}"
913-
914-
# Extract filename from filepath
915-
import os
917+
if fos.is_local(filepath):
918+
download_url = f"http://localhost:5151/media?filepath={filepath}"
919+
else:
920+
download_url = filepath
916921

917922
filename = os.path.basename(filepath)
918923

@@ -932,7 +937,6 @@ def resolve_output(self, ctx):
932937
# Create a download button view
933938
download_url = ctx.results.get("download_url")
934939
filename = ctx.results.get("filename")
935-
print(download_url)
936940
download_button = types.Button(
937941
label="Download Image",
938942
icon="download",
@@ -950,10 +954,6 @@ def resolve_output(self, ctx):
950954
return types.Property(outputs)
951955

952956

953-
# an example operator that allows a user to select a sample
954-
# then in the output they can click a button that downloads the image
955-
956-
957957
def register(p):
958958
p.register(MessagesExample)
959959
p.register(SimpleInputExample)

0 commit comments

Comments
 (0)