From 3f789b4928571f0823631352102bdfd262105bbe Mon Sep 17 00:00:00 2001 From: nanguage Date: Mon, 19 Feb 2024 15:59:29 +0100 Subject: [PATCH] fix the bug caused by not ready to run --- README.md | 11 +++++++++++ src/main.ts | 7 +++++++ src/stores/run.ts | 3 +++ 3 files changed, 21 insertions(+) diff --git a/README.md b/README.md index 936d10f..e325240 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Online instance: [ufish-web](https://ufish-team.github.io/#/) Usage example: ```Python +import numpy as np ufish = await api.createWindow("https://ufish-team.github.io/") img = np.random.rand(100, 100) # generate a random image out = await ufish.predict(img) # predict the spots @@ -17,6 +18,16 @@ print(out.enhanced.shape) print(out.spots.shape) ``` +### Full API List + +| Method | Parameters | Description | +| --- | --- | --- | +| `predict` | `img: np.ndarray` | Predict the spots in the input image. | +| `waitReady` | | Wait until the model is ready. | +| `setInputImage` | `img: np.ndarray; name: string` | Set the input image. | +| `getOutput` | | Get the output of the model. It's an object contain `enhanced: np.ndarray` and `spots: np.ndarray` fields | +| `runPredict` | | Run the prediction. | + ## Development ```sh diff --git a/src/main.ts b/src/main.ts index 5fe4271..4e48323 100644 --- a/src/main.ts +++ b/src/main.ts @@ -35,6 +35,11 @@ async function createApi() { console.log("U-FISH is ready.") } + async function waitRunable() { + const runStore = useRunStore() + await runStore.waitRunable() + } + async function run() { const runStore = useRunStore() await runStore.run() @@ -56,6 +61,7 @@ async function createApi() { } async function predict(inputImage: object) { + await waitRunable() await setInputImage(inputImage, "input") await run() return await getOutput() @@ -64,6 +70,7 @@ async function createApi() { return { "run": async () => {}, "setup": setup, + "waitReady": waitRunable, "runPredict": run, "setInputImage": setInputImage, "getOutput": getOutput, diff --git a/src/stores/run.ts b/src/stores/run.ts index 216e0c6..44521a7 100644 --- a/src/stores/run.ts +++ b/src/stores/run.ts @@ -40,6 +40,9 @@ export const useRunStore = defineStore("run", { outputGetable: false, }), actions: { + async waitRunable() { + await waitRunable(); + }, async run() { await waitRunable(); this.runQueryCount += 1;