Skip to content
Closed
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
19 changes: 17 additions & 2 deletions app/packages/annotation/src/providers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,34 @@ interface WorkerMessage<Req, Res> {
response: Res;
}

export interface DownloadProgress {
file: "encoder" | "decoder";
loaded: number;
total: number;
}

/** Maps worker message types to their request/response payloads. */
export type WorkerMessages = {
loadModel: WorkerMessage<Record<string, never>, void>;
embedAndDecode: WorkerMessage<InferenceRequest, InferenceResult>;
};

/** One-way worker-to-main-thread notification payloads. */
export type WorkerNotifications = {
progress: DownloadProgress;
warning: string;
};

export type WorkerMessageType = keyof WorkerMessages;
export type WorkerRequest<T extends WorkerMessageType> = WorkerMessages[T]["request"];
export type WorkerResponse<T extends WorkerMessageType> = WorkerMessages[T]["response"];

export type DownloadProgressCallback = (progress: DownloadProgress) => void;
export type WarningCallback = (message: string) => void;

export interface AnnotationProvider {
initialize(): Promise<void>;
initialize(onProgress?: DownloadProgressCallback, onWarning?: WarningCallback): Promise<void>;
infer(request: InferenceRequest): Promise<InferenceResult>;
abort(): void;
dispose(): void;
}
}
34 changes: 2 additions & 32 deletions app/packages/operators/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,14 +1026,6 @@ export function useOperatorBrowser() {
};
}

/**
* Result of attempting to load a local or remote operator.
*/
export enum OperatorLoadResult {
SUCCESS = "SUCCESS",
NOT_FOUND = "NOT_FOUND",
}

/**
* @param uri - The URI of the operator to execute.
* @param handlers - The optional handlers for the operator.
Expand Down Expand Up @@ -1077,21 +1069,10 @@ export function useOperatorExecutor(uri, handlers: any = {}) {
uri = resolveOperatorURI(uri, { keepMethod: true });

let operator;
let loadResult: OperatorLoadResult;
try {
operator = getLocalOrRemoteOperator(uri).operator;
loadResult = OperatorLoadResult.SUCCESS;
} catch (err) {
// operator does not exist
operator = {};
loadResult = OperatorLoadResult.NOT_FOUND;
}

// If the operator fails to load AND the consumer tries to call execute,
// this error gets set and will be thrown on the next render
const [resolutionError, setResolutionError] = useState<Error | null>(null);
if (resolutionError) {
throw resolutionError;
}

const [isExecuting, setIsExecuting] = useState(false);
Expand All @@ -1117,16 +1098,6 @@ export function useOperatorExecutor(uri, handlers: any = {}) {

const execute = useRecoilCallback(
(state) => async (paramOverrides, options?: OperatorExecutorOptions) => {
// exit early if operator did not load successfully
if (loadResult !== OperatorLoadResult.SUCCESS) {
// defer throw to next render rather than throwing directly;
// this better contextualizes the cause of the error
setResolutionError(
new Error(`Operator "${uri}" not found or not accessible`)
);
return;
}

const { delegationTarget, requestDelegation, skipOutput, callback } =
options || {};
setIsExecuting(true);
Expand Down Expand Up @@ -1183,7 +1154,7 @@ export function useOperatorExecutor(uri, handlers: any = {}) {
setHasExecuted(true);
setIsExecuting(false);
},
[currentSample, context, loadResult]
[currentSample, context]
);
return {
isExecuting,
Expand All @@ -1195,7 +1166,6 @@ export function useOperatorExecutor(uri, handlers: any = {}) {
clear,
hasResultOrError: result || error,
isDelegated,
loadResult,
};
}

Expand Down Expand Up @@ -1285,4 +1255,4 @@ export function useOperatorPlacements(place: Places) {
export const activePanelsEventCountAtom = atom({
key: "activePanelsEventCountAtom",
default: new Map<string, number>(),
});
});
26 changes: 12 additions & 14 deletions fiftyone/server/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,6 @@ def _match_label_tags(view: foc.SampleCollection, label_tags):
values = label_tags["values"]
exclude = label_tags["exclude"]
matching = label_tags["isMatching"]

if not exclude or matching:
operator = "$nor" if exclude else "$or"
view = view.mongo(
Expand All @@ -991,17 +990,16 @@ def _match_label_tags(view: foc.SampleCollection, label_tags):
]
)

if not matching:
if exclude:
view = view.exclude_labels(
tags=values,
omit_empty=False,
fields=view._get_label_fields(),
)
else:
view = view.select_labels(
tags=values,
fields=view._get_label_fields(),
)
if not matching and exclude:
view = view.exclude_labels(
tags=label_tags["values"],
omit_empty=False,
fields=view._get_label_fields(),
)
elif not matching:
view = view.select_labels(
tags=label_tags["values"],
fields=view._get_label_fields(),
)

return view
return view
Loading