Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Local Development Scripts #127

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

4 changes: 2 additions & 2 deletions electron_app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions electron_app/src/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -129,4 +131,4 @@ function bind_window_bridge(w) {
}


export { start_bridge, bind_window_bridge }
export { start_bridge, bind_window_bridge }
20 changes: 20 additions & 0 deletions install-local-dev-2.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link

@Leland Leland Oct 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm does not ship with macOS. Consider checking for the existence of these commands upfront, and providing users with better context, with e.g.

if ! [ -x "$(command -v npm)" ]; then
  echo 'Error: npm is not installed.' >&2
  exit 1
fi


echo ">> Starting electron app"
npm run electron:serve

34 changes: 34 additions & 0 deletions install-local-dev.sh
Original file line number Diff line number Diff line change
@@ -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 ..
Comment on lines +5 to +13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pushd and popd instead of having to manually move around. (This script ends without returning the user to the root of the directory, by the by! With this, you can just popd at the end and leave the user at the beginning)

Suggested change
# 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 ..
# Download stable diffusion info
pushd 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
pushd stable-diffusion
git checkout apple-mps-support
popd


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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wget is not available on macOS by default, use curl instead for portability

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conda does not ship with macOS


echo ">> Now run 'conda activate diffusionbee'"
echo ">> Followed by './install-local-dev-2.sh'"