-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhypha_microscope_plugin.imjoy.html
89 lines (75 loc) · 3.27 KB
/
hypha_microscope_plugin.imjoy.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<docs lang="markdown">
[TODO: write documentation for this plugin.]
</docs>
<config lang="json">
{
"name": "UC2-microscope-chatbot",
"type": "web-python",
"version": "0.1.0",
"description": "This plugin controls UC2 microscope with chatbot. And will be put on microscope control web GUI",
"tags": [],
"ui": "",
"cover": "",
"inputs": null,
"outputs": null,
"flags": [],
"icon": "extension",
"api_version": "0.1.8",
"env": "",
"permissions": [],
"requirements": [],
"dependencies": []
}
</config>
<script lang="python">
import asyncio
from imjoy import api
async def setup():
# Use micropip to install pydantic asynchronously
import micropip
await micropip.install("pydantic")
# Now that pydantic is installed, we can safely import it
from pydantic import BaseModel, Field
class MoveByDistanceInput(BaseModel):
"""Move the stage by a specified distance, the unit of distance is millimeters, so you need to input the distance in millimeters."""
x: float = Field(description="Move the stage along X axis.")
y: float = Field(description="Move the stage along Y axis.")
z: float = Field(description="Move the stage along Z axis.")
class SnapImageInput(BaseModel):
"""Snap an image from microscope."""
exposure: int = Field(description="Set the microscope camera's exposure time. and the time unit is ms, so you need to input the time in miliseconds.")
async def move_stage_by_distance(kwargs):
config = MoveByDistanceInput(**kwargs)
UC2_svc.move_by_distance(config.x, config.y, config.z)
print(config.x, config.y, config.z)
return "Moved the stage!"
async def snap_image(kwargs):
config = SnapImageInput(**kwargs)
UC2_image = await UC2_svc.snap()
viewer = await api.createWindow(type="itk-vtk-viewer", src="https://kitware.github.io/itk-vtk-viewer/app")
await viewer.setImage(UC2_image)
return "Here is the image"
global UC2_svc
from imjoy_rpc.hypha import connect_to_server
UC2_server = await connect_to_server({"server_url": "https://ai.imjoy.io/"})
UC2_svc = await UC2_server.get_service("microscope-control-UC2")
chatbot = await api.createWindow(src="https://bioimage.io/chat", name="BioImage.IO Chatbot")
async def get_schema():
return {
"move_by_distance": MoveByDistanceInput.schema(),
"snap_image": SnapImageInput.schema()
}
extension = {
"_rintf": True,
"id": "UC2-control",
"name": "UC2 Microscope Control",
"description": "Control the microscope based on the user's request. Now you can move the microscope stage, and snap an image.",
"get_schema": get_schema,
"tools": {
"move_by_distance": move_stage_by_distance,
"snap_image": snap_image,
}
}
await chatbot.registerExtension(extension)
api.export({"setup": setup})
</script>