Skip to content

Commit

Permalink
add chatbot extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanguage committed Mar 29, 2024
1 parent adfb8d7 commit 2a40523
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
87 changes: 87 additions & 0 deletions public/chatbot-extension.imjoy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<docs>
[TODO: write documentation for this plugin.]
</docs>

<config lang="json">
{
"name": "chatbot-ufish",
"type": "web-worker",
"tags": [],
"ui": "",
"version": "0.1.0",
"cover": "",
"description": "Register ufish-web to chatbot",
"icon": "extension",
"inputs": null,
"outputs": null,
"api_version": "0.1.8",
"env": "",
"permissions": [],
"requirements": [],
"dependencies": []
}
</config>

<script lang="javascript">
class ImJoyPlugin {
async setup() {
if (api.registerChatbotExtension) {
const chatbot = api
await this.registerExtensions(chatbot.registerChatbotExtension)
} else {
let chatbot = await api.getWindow("BioImage.IO Chatbot")
if (chatbot) {
await this.registerExtensions(chatbot.registerExtension)
} else {
chatbot = await api.createWindow({src: "https://chat.bioimage.io/public/apps/bioimageio-chatbot-client/chat", name: "BioImage.IO Chatbot"})
await this.registerExtensions(chatbot.registerExtension)
}
}
}

async registerExtensions(register) {
await register({
_rintf: true,
name: "runUfish",
description: "The extension allow chatbot run U-FISH web client",
async get_schema() {
return {
type: "object",
title: "RunUfish",
description: "Run U-FISH web client",
properties: {
},
};
},
async execute(config) {
let client = await api.getWindow("ufish");
if (!client) {
client = await api.createWindow({
src: "https://ufish-team.github.io/",
name: "ufish",
});
await client.waitReady();
}
await client.runPredict();
const output = await client.getOutput();
return "Done"
},
})

api.log('initialized')
}

async run(ctx) {
let client = await api.getWindow("ufish");
if (!client) {
client = await api.createWindow({
src: "https://ufish-team.github.io/",
name: "ufish",
});
await client.waitReady();
}
}
}

api.export(new ImJoyPlugin())
</script>
3 changes: 3 additions & 0 deletions public/plugins/ufish.imjoy.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@
csv_bytes = fake_csv_file.getvalue().encode()
num_spots = df.shape[0]
return enh_bytes, csv_bytes, num_spots

async def get_spots(self):
return self.spots

async def scale_image(self):
image = self.image
Expand Down
3 changes: 2 additions & 1 deletion src/views/PredictView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ export default {
}
if (isPluginMode()) {
const spots = await plugin.value.get_spots()
runStore.setOutput({
enhanced: outImg,
spots: coords,
spots: spots,
})
}
runInfoText.value = `Done, ${numSpots} spots detected.`
Expand Down

0 comments on commit 2a40523

Please sign in to comment.