From 2daca33e425bfebb0f2f302330e9a4029310d093 Mon Sep 17 00:00:00 2001 From: ngundotra Date: Sun, 25 Sep 2022 22:05:12 -0400 Subject: [PATCH 1/5] build: add build script for local development --- build.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..1a58be78 --- /dev/null +++ b/build.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +set -e + +# Download stable diffusion info +cd backends/stable_diffusion_torch + +echo "Downloading stable diffusion code" + +# Download the m1-compatible Stable Diffusion sampling infrastructure +git clone https://github.com/magnusviri/stable-diffusion.git +cd stable-diffusion +git checkout apple-mps-support +cd .. + + +echo "Downloading python dependencies" + +# Create fresh python environment +conda create --name diffusionbee +conda activate diffusionbee +conda install pytorch torchvision torchaudio -c pytorch-nightly + +echo "Downloading custom python dependencies, might have to pass (i) to ignore existing packages" +# You will have to pass (i) for each +pip install -r requirements.txt + +echo "Downloading text (CLIP) tokenizer" +# Download the CLIP tokenizer from huggingface hub +git clone https://huggingface.co/openai/clip-vit-base-patch32 +mkdir -p HF_weights/ +mv clip-vit-base-patch32 HF_weights/clip_tokenizer + +echo "Downloading model weights (4gb, may take awhile)" +# Download v1.4 model weights (so you can run `python txt2img.py` locally when testing) +wget "https://me.cmdr2.org/stable-diffusion-ui/sd-v1-4.ckpt" -O sd-v1-4.ckpt +mkdir -p models/ldm/stable-diffusion-v1/ +ln -s sd-v1-4.ckpt models/ldm/stable-diffusion-v1/model.ckpt + +cd ../.. + +echo "Setting up electron app" +cd electron_app +npm i + +echo "Starting electron app" +npm run electron:serve + From 0ddd45ffa2b7f02027b0702740bcb6573a729b6d Mon Sep 17 00:00:00 2001 From: ngundotra Date: Sun, 25 Sep 2022 22:37:47 -0400 Subject: [PATCH 2/5] local-dev: process.env should provide FAKE backend, otherwise use local build --- electron_app/src/bridge.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/electron_app/src/bridge.js b/electron_app/src/bridge.js index d6551f09..2e19d0ef 100644 --- a/electron_app/src/bridge.js +++ b/electron_app/src/bridge.js @@ -12,7 +12,9 @@ function start_bridge() { console.log("starting briddddd") const fs = require('fs') - let script_path = process.env.PY_SCRIPT || "./src/fake_backend.py"; + // PY_SCRIPT_DEV can be set to "./src/fake_backend.py" when developing the electron app + // to simulate the model inference, without actually executing the code + let script_path = process.env.PY_SCRIPT_DEV || "../backends/stable_diffusion_torch/txt2img.py"; if (fs.existsSync(script_path)) { python = require('child_process').spawn('python3', [script_path]); @@ -129,4 +131,4 @@ function bind_window_bridge(w) { } -export { start_bridge, bind_window_bridge } \ No newline at end of file +export { start_bridge, bind_window_bridge } From 118641aba445dd969534955e00a9542a7614d59e Mon Sep 17 00:00:00 2001 From: ngundotra Date: Sun, 25 Sep 2022 22:38:33 -0400 Subject: [PATCH 3/5] local-dev: remove symlinked file --- .../models/ldm/stable-diffusion-v1/model.ckpt | 1 - 1 file changed, 1 deletion(-) delete mode 120000 backends/stable_diffusion_torch/models/ldm/stable-diffusion-v1/model.ckpt diff --git a/backends/stable_diffusion_torch/models/ldm/stable-diffusion-v1/model.ckpt b/backends/stable_diffusion_torch/models/ldm/stable-diffusion-v1/model.ckpt deleted file mode 120000 index 174e5d9b..00000000 --- a/backends/stable_diffusion_torch/models/ldm/stable-diffusion-v1/model.ckpt +++ /dev/null @@ -1 +0,0 @@ -/Users/divamgupta/Downloads/sd-v1-4.ckpt \ No newline at end of file From 856e7a9f894dcc6aa988e4824c5e5af2e3bb774a Mon Sep 17 00:00:00 2001 From: ngundotra Date: Sun, 25 Sep 2022 22:39:15 -0400 Subject: [PATCH 4/5] local-dev: add local dev install scripts for the curious hacker --- install-local-dev-2.sh | 20 ++++++++++++++++++++ install-local-dev.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 install-local-dev-2.sh create mode 100755 install-local-dev.sh diff --git a/install-local-dev-2.sh b/install-local-dev-2.sh new file mode 100755 index 00000000..069f8bb4 --- /dev/null +++ b/install-local-dev-2.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +cd backends/stable_diffusion_torch/ + +echo ">> Installing pytorch" +conda install pytorch torchvision torchaudio -c pytorch-nightly + +echo ">> Downloading custom python dependencies, might have to pass (i) to ignore existing packages" +pip install -r requirements.txt + +cd ../.. + +echo ">> Setting up electron app" +cd electron_app +npm i + +echo ">> Starting electron app" +npm run electron:serve + diff --git a/install-local-dev.sh b/install-local-dev.sh new file mode 100755 index 00000000..cde67299 --- /dev/null +++ b/install-local-dev.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +set -e + +# Download stable diffusion info +cd backends/stable_diffusion_torch + +echo ">> Downloading stable diffusion code" +# Download the m1-compatible Stable Diffusion sampling infrastructure +git clone https://github.com/magnusviri/stable-diffusion.git +cd stable-diffusion +git checkout apple-mps-support +cd .. + +echo ">> Downloading text (CLIP) tokenizer" +# Download the CLIP tokenizer from huggingface hub +git clone https://huggingface.co/openai/clip-vit-base-patch32 +mkdir -p HF_weights/ +mv clip-vit-base-patch32 HF_weights/clip_tokenizer + +echo ">> Downloading model weights (4gb, may take awhile)" +# Download v1.4 model weights (so you can run `python txt2img.py` locally when testing) +wget "https://me.cmdr2.org/stable-diffusion-ui/sd-v1-4.ckpt" -O sd-v1-4.ckpt +mkdir -p models/ldm/stable-diffusion-v1/ +ln -s sd-v1-4.ckpt models/ldm/stable-diffusion-v1/model.ckpt + + +echo ">> Creating environment diffusion bee" +# Create fresh python environment +conda create --name diffusionbee + +echo ">> Now run 'conda activate diffusionbee'" +echo ">> Followed by './install-local-dev-2.sh'" + From 81ba60e29d9699609dead8e628282abc10ead04a Mon Sep 17 00:00:00 2001 From: ngundotra Date: Sun, 25 Sep 2022 22:39:50 -0400 Subject: [PATCH 5/5] local-dev: remove bad build.sh script, update package-lock.json --- build.sh | 48 ---------------------------------- electron_app/package-lock.json | 4 +-- 2 files changed, 2 insertions(+), 50 deletions(-) delete mode 100755 build.sh diff --git a/build.sh b/build.sh deleted file mode 100755 index 1a58be78..00000000 --- a/build.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash - -set -e - -# Download stable diffusion info -cd backends/stable_diffusion_torch - -echo "Downloading stable diffusion code" - -# Download the m1-compatible Stable Diffusion sampling infrastructure -git clone https://github.com/magnusviri/stable-diffusion.git -cd stable-diffusion -git checkout apple-mps-support -cd .. - - -echo "Downloading python dependencies" - -# Create fresh python environment -conda create --name diffusionbee -conda activate diffusionbee -conda install pytorch torchvision torchaudio -c pytorch-nightly - -echo "Downloading custom python dependencies, might have to pass (i) to ignore existing packages" -# You will have to pass (i) for each -pip install -r requirements.txt - -echo "Downloading text (CLIP) tokenizer" -# Download the CLIP tokenizer from huggingface hub -git clone https://huggingface.co/openai/clip-vit-base-patch32 -mkdir -p HF_weights/ -mv clip-vit-base-patch32 HF_weights/clip_tokenizer - -echo "Downloading model weights (4gb, may take awhile)" -# Download v1.4 model weights (so you can run `python txt2img.py` locally when testing) -wget "https://me.cmdr2.org/stable-diffusion-ui/sd-v1-4.ckpt" -O sd-v1-4.ckpt -mkdir -p models/ldm/stable-diffusion-v1/ -ln -s sd-v1-4.ckpt models/ldm/stable-diffusion-v1/model.ckpt - -cd ../.. - -echo "Setting up electron app" -cd electron_app -npm i - -echo "Starting electron app" -npm run electron:serve - diff --git a/electron_app/package-lock.json b/electron_app/package-lock.json index f2451c53..b8d28399 100644 --- a/electron_app/package-lock.json +++ b/electron_app/package-lock.json @@ -1,12 +1,12 @@ { "name": "DiffusionBee", - "version": "0.1.0", + "version": "0.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "DiffusionBee", - "version": "0.1.0", + "version": "0.3.0", "hasInstallScript": true, "dependencies": { "@codekraft-studio/vue-record": "^0.0.3",