Spaces:
Sleeping
Sleeping
Relative path to scribble bird
Browse files- public-apps/sd_controlnet.livemd +64 -10
public-apps/sd_controlnet.livemd
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
<!-- livebook:{"app_settings":{"access_type":"public","auto_shutdown_ms":3600000,"show_source":true,"slug":"controlnet"}
|
| 2 |
|
| 3 |
# SD ControlNet
|
| 4 |
|
|
@@ -6,8 +6,16 @@
|
|
| 6 |
Mix.install([
|
| 7 |
{:bumblebee, git: "https://github.com/joelpaulkoch/bumblebee.git", branch: "SD_controlnet"},
|
| 8 |
{:axon, "~> 0.6.0", override: true},
|
| 9 |
-
{:nx,
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
{:kino, "~> 0.12.3"},
|
| 12 |
{:nx_image, "~> 0.1.2"},
|
| 13 |
{:stb_image, "~> 0.6.5"}
|
|
@@ -62,13 +70,63 @@ serving =
|
|
| 62 |
)
|
| 63 |
```
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
| 66 |
|
| 67 |
```elixir
|
| 68 |
-
Kino.Text.new("Scribble
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
```
|
| 70 |
|
| 71 |
```elixir
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
cond_inp = Kino.Input.image("cond_image", size: {512, 512}, fit: :pad)
|
| 73 |
```
|
| 74 |
|
|
@@ -80,9 +138,7 @@ cond_image_tensor =
|
|
| 80 |
|> Nx.from_binary(:u8)
|
| 81 |
|> Nx.reshape({512, 512, 3})
|
| 82 |
|> NxImage.to_continuous(0, 1)
|
| 83 |
-
```
|
| 84 |
|
| 85 |
-
```elixir
|
| 86 |
prompt_input =
|
| 87 |
Kino.Input.text("Prompt", default: "a bird, high quality, detailed")
|
| 88 |
|
|
@@ -92,10 +148,8 @@ Kino.Layout.grid([prompt_input, negative_prompt_input])
|
|
| 92 |
```
|
| 93 |
|
| 94 |
```elixir
|
| 95 |
-
Kino.Text.new("Generate image ...")
|
| 96 |
-
```
|
| 97 |
|
| 98 |
-
```elixir
|
| 99 |
prompt = Kino.Input.read(prompt_input)
|
| 100 |
negative_prompt = Kino.Input.read(negative_prompt_input)
|
| 101 |
|
|
|
|
| 1 |
+
<!-- livebook:{"app_settings":{"access_type":"public","auto_shutdown_ms":3600000,"show_source":true,"slug":"controlnet"}} -->
|
| 2 |
|
| 3 |
# SD ControlNet
|
| 4 |
|
|
|
|
| 6 |
Mix.install([
|
| 7 |
{:bumblebee, git: "https://github.com/joelpaulkoch/bumblebee.git", branch: "SD_controlnet"},
|
| 8 |
{:axon, "~> 0.6.0", override: true},
|
| 9 |
+
{:nx,
|
| 10 |
+
github: "elixir-nx/nx",
|
| 11 |
+
ref: "bead39ccd703cd9243e985659b2905eea8977862",
|
| 12 |
+
sparse: "nx",
|
| 13 |
+
override: true},
|
| 14 |
+
{:exla,
|
| 15 |
+
github: "elixir-nx/nx",
|
| 16 |
+
ref: "bead39ccd703cd9243e985659b2905eea8977862",
|
| 17 |
+
sparse: "exla",
|
| 18 |
+
override: true},
|
| 19 |
{:kino, "~> 0.12.3"},
|
| 20 |
{:nx_image, "~> 0.1.2"},
|
| 21 |
{:stb_image, "~> 0.6.5"}
|
|
|
|
| 70 |
)
|
| 71 |
```
|
| 72 |
|
| 73 |
+
<!-- livebook:{"branch_parent_index":0} -->
|
| 74 |
+
|
| 75 |
+
## Scribble bird
|
| 76 |
|
| 77 |
```elixir
|
| 78 |
+
Kino.Text.new("Scribble Bird")
|
| 79 |
+
livebook_dir = Path.absname(__DIR__)
|
| 80 |
+
|
| 81 |
+
bird_file_input =
|
| 82 |
+
Kino.Input.text("Bird file path", default: livebook_dir <> "/scribble_bird.png")
|
| 83 |
```
|
| 84 |
|
| 85 |
```elixir
|
| 86 |
+
bird_file = Kino.Input.read(bird_file_input)
|
| 87 |
+
|
| 88 |
+
bird_image = StbImage.read_file!(bird_file) |> StbImage.to_nx()
|
| 89 |
+
|
| 90 |
+
bird_image_tensor =
|
| 91 |
+
bird_image
|
| 92 |
+
|> Nx.reshape({512, 512, 3})
|
| 93 |
+
|> NxImage.to_continuous(0, 1)
|
| 94 |
+
|
| 95 |
+
Kino.Image.new(bird_image)
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
```elixir
|
| 99 |
+
bird_prompt = "a bird, high quality, detailed"
|
| 100 |
+
bird_negative_prompt = "ugly, low quality, blurry"
|
| 101 |
+
|
| 102 |
+
Kino.Layout.grid([
|
| 103 |
+
Kino.Text.new("prompt: " <> bird_prompt),
|
| 104 |
+
Kino.Text.new("negative prompt:" <> bird_negative_prompt)
|
| 105 |
+
])
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
<!-- livebook:{"reevaluate_automatically":true} -->
|
| 109 |
+
|
| 110 |
+
```elixir
|
| 111 |
+
Kino.Text.new("Generate image ...")
|
| 112 |
+
|
| 113 |
+
output =
|
| 114 |
+
Nx.Serving.run(serving, %{
|
| 115 |
+
prompt: bird_prompt,
|
| 116 |
+
negative_prompt: bird_negative_prompt,
|
| 117 |
+
controlnet_conditioning: bird_image_tensor
|
| 118 |
+
})
|
| 119 |
+
|
| 120 |
+
for result <- output.results do
|
| 121 |
+
Kino.Image.new(result.image)
|
| 122 |
+
end
|
| 123 |
+
|> Kino.Layout.grid(columns: 2)
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
## Your own input
|
| 127 |
+
|
| 128 |
+
```elixir
|
| 129 |
+
Kino.Text.new("Scribble image") |> Kino.render()
|
| 130 |
cond_inp = Kino.Input.image("cond_image", size: {512, 512}, fit: :pad)
|
| 131 |
```
|
| 132 |
|
|
|
|
| 138 |
|> Nx.from_binary(:u8)
|
| 139 |
|> Nx.reshape({512, 512, 3})
|
| 140 |
|> NxImage.to_continuous(0, 1)
|
|
|
|
| 141 |
|
|
|
|
| 142 |
prompt_input =
|
| 143 |
Kino.Input.text("Prompt", default: "a bird, high quality, detailed")
|
| 144 |
|
|
|
|
| 148 |
```
|
| 149 |
|
| 150 |
```elixir
|
| 151 |
+
Kino.Text.new("Generate image ...") |> Kino.render()
|
|
|
|
| 152 |
|
|
|
|
| 153 |
prompt = Kino.Input.read(prompt_input)
|
| 154 |
negative_prompt = Kino.Input.read(negative_prompt_input)
|
| 155 |
|