system HF Staff commited on
Commit
f143b40
·
verified ·
1 Parent(s): 93a00c5

Deploy hyper3labs/HyperView-VisA-Manufacturing from Hyper3Labs/hyperview-spaces@f672a3d

Browse files
.hyperview/extensions/manufacturing-readout/panel.js CHANGED
@@ -1,9 +1,10 @@
1
  const sdk = globalThis.HyperViewPanelSDK;
2
- if (!sdk) throw new Error("HyperViewPanelSDK is not available on window.");
 
 
3
 
4
- const { React, components, hooks } = sdk;
5
- const { Panel } = components;
6
- const { usePanelCommands, usePanelProps, usePanelRuntimeState } = hooks;
7
 
8
  const colors = {
9
  panelBg: "#10151f",
@@ -476,17 +477,27 @@ function WalkthroughCard({ item, models, onSelectQuery, loadingKey, activeModelK
476
  }
477
 
478
  export default function ManufacturingPanel() {
479
- const props = usePanelProps() || {};
480
- const commands = usePanelCommands();
481
- const runtimeState = usePanelRuntimeState ? usePanelRuntimeState() : {};
 
482
  const models = normalizeModels(props.models);
483
  const examples = Array.isArray(props.examples) ? props.examples : [];
484
  const primaryExample = examples.find((item) => item.id === "fryum") || examples[0] || null;
485
  const [loadingKey, setLoadingKey] = React.useState(null);
486
  const [panelError, setPanelError] = React.useState(null);
487
- const [activeChoice, setActiveChoice] = React.useState(null);
488
- const [activeModelKey, setActiveModelKey] = React.useState(null);
489
- const statusChoice = choiceFromSimilarity(runtimeState.activeSimilarityQuery, examples, models) || activeChoice;
 
 
 
 
 
 
 
 
 
490
 
491
  const onSelectQuery = React.useCallback(
492
  async (sampleId, model) => {
@@ -494,35 +505,23 @@ export default function ManufacturingPanel() {
494
  setPanelError("Could not show neighbors: this example is missing a query or layout key.");
495
  return;
496
  }
497
- if (!commands) {
498
- setPanelError("Could not show neighbors: HyperView panel commands are unavailable in this panel host.");
499
- return;
500
- }
501
  const choiceKey = `${sampleId}:${model.key}`;
502
  const item = examples.find((example) => example.queryId === sampleId);
503
  const metric = advantageMetric(model.key, item?.id);
504
- const nextChoice = {
505
- modelKey: model.key,
506
- modelName: model.displayName,
507
- queryLabel: title(item?.queryLabel || "fryum"),
508
- metricLine: metric?.line || null,
509
- };
510
  setPanelError(null);
511
- setActiveModelKey(model.key);
512
- setActiveChoice(nextChoice);
513
  setLoadingKey(choiceKey);
514
  try {
515
- await commands.setActiveLayout(model.layoutKey, { persist: true });
516
- await commands.showSimilar({
517
- sampleId,
518
- layoutKey: model.layoutKey,
519
- k: 10,
520
- source: `manufacturing-demo:${model.key}`,
521
- focus: "samples",
522
- persist: true,
523
  });
524
- setActiveChoice(nextChoice);
525
- setActiveModelKey(model.key);
526
  } catch (error) {
527
  const message = error instanceof Error ? error.message : String(error);
528
  setPanelError(`Could not show neighbors: ${message}`);
@@ -530,11 +529,11 @@ export default function ManufacturingPanel() {
530
  setLoadingKey(null);
531
  }
532
  },
533
- [commands, examples],
534
  );
535
 
536
  return React.createElement(
537
- Panel,
538
  {
539
  style: {
540
  background: colors.panelBg,
 
1
  const sdk = globalThis.HyperViewPanelSDK;
2
+ if (!sdk || sdk.version !== "2") {
3
+ throw new Error("HyperViewPanelSDK v2 is not available on window.");
4
+ }
5
 
6
+ const { React, hooks } = sdk;
7
+ const { useActiveLayout, useCommandClient, usePanelActions, usePanelState } = hooks;
 
8
 
9
  const colors = {
10
  panelBg: "#10151f",
 
477
  }
478
 
479
  export default function ManufacturingPanel() {
480
+ const { props = {}, state = {}, patchState } = usePanelState();
481
+ const { runCommand } = useCommandClient();
482
+ const { setActiveLayout } = useActiveLayout();
483
+ const { focusPanel } = usePanelActions();
484
  const models = normalizeModels(props.models);
485
  const examples = Array.isArray(props.examples) ? props.examples : [];
486
  const primaryExample = examples.find((item) => item.id === "fryum") || examples[0] || null;
487
  const [loadingKey, setLoadingKey] = React.useState(null);
488
  const [panelError, setPanelError] = React.useState(null);
489
+ const activeModelKey = typeof state.activeModelKey === "string" ? state.activeModelKey : null;
490
+ const activeSampleId = typeof state.activeSampleId === "string" ? state.activeSampleId : null;
491
+ const statusChoice = choiceFromSimilarity(
492
+ activeSampleId
493
+ ? {
494
+ anchor_sample_id: activeSampleId,
495
+ source: `manufacturing-demo:${activeModelKey || ""}`,
496
+ }
497
+ : null,
498
+ examples,
499
+ models,
500
+ );
501
 
502
  const onSelectQuery = React.useCallback(
503
  async (sampleId, model) => {
 
505
  setPanelError("Could not show neighbors: this example is missing a query or layout key.");
506
  return;
507
  }
 
 
 
 
508
  const choiceKey = `${sampleId}:${model.key}`;
509
  const item = examples.find((example) => example.queryId === sampleId);
510
  const metric = advantageMetric(model.key, item?.id);
 
 
 
 
 
 
511
  setPanelError(null);
 
 
512
  setLoadingKey(choiceKey);
513
  try {
514
+ await setActiveLayout(model.layoutKey);
515
+ await runCommand("collection.neighbors.create", {
516
+ args: {
517
+ sample_id: sampleId,
518
+ layout_key: model.layoutKey,
519
+ k: 10,
520
+ source: `manufacturing-demo:${model.key}`,
521
+ },
522
  });
523
+ await patchState({ activeModelKey: model.key, activeSampleId: sampleId });
524
+ await focusPanel("manufacturing-neighbors");
525
  } catch (error) {
526
  const message = error instanceof Error ? error.message : String(error);
527
  setPanelError(`Could not show neighbors: ${message}`);
 
529
  setLoadingKey(null);
530
  }
531
  },
532
+ [examples, focusPanel, patchState, runCommand, setActiveLayout],
533
  );
534
 
535
  return React.createElement(
536
+ "main",
537
  {
538
  style: {
539
  background: colors.panelBg,
README.md CHANGED
@@ -56,7 +56,7 @@ Run locally from the HyperView repo:
56
 
57
  ```bash
58
  VISA_SAMPLES_PER_CATEGORY=12 HYPERVIEW_PORT=6265 \
59
- uv run python hyperview-spaces/spaces/manufacturing-visa-reference-clip-hyper3clip/demo.py
60
  ```
61
 
62
  The Docker image installs the bundled latest HyperView wheel for this repo and
 
56
 
57
  ```bash
58
  VISA_SAMPLES_PER_CATEGORY=12 HYPERVIEW_PORT=6265 \
59
+ uv run python hyperview-spaces/demos/manufacturing-visa-reference-clip-hyper3clip/demo.py
60
  ```
61
 
62
  The Docker image installs the bundled latest HyperView wheel for this repo and
demo.py CHANGED
@@ -17,7 +17,6 @@ from typing import Any
17
  from PIL import Image, ImageOps
18
 
19
  import hyperview as hv
20
- from hyperview.core.dataset import Sample
21
 
22
  SPACE_DIR = Path(__file__).resolve().parent
23
  SPACE_HOST = os.environ.get("HYPERVIEW_HOST", "127.0.0.1")
@@ -249,7 +248,7 @@ def select_visa_records() -> list[dict[str, Any]]:
249
  def add_visa_samples(dataset: hv.Dataset) -> None:
250
  existing_ids = {sample.id for sample in dataset.samples}
251
  media_dir = media_root()
252
- samples: list[Sample] = []
253
  for record in select_visa_records():
254
  sample_id = safe_sample_id(record["category"], record["split_name"], record["row_index"], record["defect_label"])
255
  destination = Path(record["local_path"]) if record.get("local_path") else media_dir / f"{sample_id}.jpg"
@@ -265,7 +264,7 @@ def add_visa_samples(dataset: hv.Dataset) -> None:
265
  "source_dataset": "BrachioLab/visa",
266
  }
267
  samples.append(
268
- Sample(
269
  id=sample_id,
270
  filepath=str(destination),
271
  label=record["category"],
 
17
  from PIL import Image, ImageOps
18
 
19
  import hyperview as hv
 
20
 
21
  SPACE_DIR = Path(__file__).resolve().parent
22
  SPACE_HOST = os.environ.get("HYPERVIEW_HOST", "127.0.0.1")
 
248
  def add_visa_samples(dataset: hv.Dataset) -> None:
249
  existing_ids = {sample.id for sample in dataset.samples}
250
  media_dir = media_root()
251
+ samples: list[hv.Sample] = []
252
  for record in select_visa_records():
253
  sample_id = safe_sample_id(record["category"], record["split_name"], record["row_index"], record["defect_label"])
254
  destination = Path(record["local_path"]) if record.get("local_path") else media_dir / f"{sample_id}.jpg"
 
264
  "source_dataset": "BrachioLab/visa",
265
  }
266
  samples.append(
267
+ hv.Sample(
268
  id=sample_id,
269
  filepath=str(destination),
270
  label=record["category"],