Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Facade node

distributed_facade_refactored.livemd

Facade node

Mix.install(
  [
    {:kino_bumblebee, "~> 0.3.0"},
    {:exla, "~> 0.5.1"}
  ],
  config: [nx: [default_backend: EXLA.Backend]]
)
:ok

Multi Model Facade

defmodule Facade do
  def run(model) do
    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..."))

        Nx.Serving.run(model.build(), Common.reshape(image))
        |> model.for_render()
        |> then(&Kino.Frame.render(frame, &1))
      end
    end)

    Kino.Layout.grid([form, frame], boxed: true, gap: 16)
  end
end
{:module, Facade, <<70, 79, 82, 49, 0, 0, 11, ...>>, {:run, 1}}
ResNet |> Facade.run()
BLIP |> Facade.run()