Distributed AI client
Mix.install(
[
{:kino_bumblebee, "~> 0.5"},
{:exla, "~> 0.9", override: true}
],
config: [nx: [default_backend: EXLA.Backend]]
)
Connect to server
{node, coockie} =
{:"3k4lpr4q-livebook-server@192.168.8.157",
:"c_vDI22GjTvH5x-kPdObzLkDYgOzk2hVfQGRck2vfh-lQV1-xirDoN"}
Node.set_cookie(node, coockie)
Node.connect(node)
Call server AI
image_input = Kino.Input.image("Image", size: {224, 224})
form = Kino.Control.form([image: image_input], submit: "Run")
frame = Kino.Frame.new()
Kino.listen(form, fn %{data: %{image: image}} ->
if image do
Kino.Frame.render(frame, Kino.Text.new("Running..."))
image = image.data |> Nx.from_binary(:u8) |> Nx.reshape({image.height, image.width, 3})
output = Nx.Serving.batched_run(ViT, image)
output.predictions
|> Enum.map(&{&1.label, &1.score})
|> Kino.Bumblebee.ScoredList.new()
|> then(&Kino.Frame.render(frame, &1))
end
end)
Kino.Layout.grid([form, frame], boxed: true, gap: 16)