Skip to content

Commit

Permalink
fix the bug caused by not ready to run
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanguage committed Feb 19, 2024
1 parent f36b391 commit 3f789b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@ 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
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
Expand Down
7 changes: 7 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -56,6 +61,7 @@ async function createApi() {
}

async function predict(inputImage: object) {
await waitRunable()
await setInputImage(inputImage, "input")
await run()
return await getOutput()
Expand All @@ -64,6 +70,7 @@ async function createApi() {
return {
"run": async () => {},
"setup": setup,
"waitReady": waitRunable,
"runPredict": run,
"setInputImage": setInputImage,
"getOutput": getOutput,
Expand Down
3 changes: 3 additions & 0 deletions src/stores/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export const useRunStore = defineStore("run", {
outputGetable: false,
}),
actions: {
async waitRunable() {
await waitRunable();
},
async run() {
await waitRunable();
this.runQueryCount += 1;
Expand Down

0 comments on commit 3f789b4

Please sign in to comment.