Skip to content

Commit

Permalink
update to 1.5, better logging, build conf json
Browse files Browse the repository at this point in the history
  • Loading branch information
divamgupta committed Apr 28, 2023
1 parent 8af38e2 commit 3b5e274
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 25 deletions.
18 changes: 9 additions & 9 deletions backends/stable_diffusion/diffusionbee_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,22 @@ def __getattr__(self, attr):


def download_weights():
global p_14 , p_14_np
global p_15 , p_15_np

print("sdbk mltl Loading Model")

is_downloaded = False
for _ in range(10):
try:

p_14 = ProgressBarDownloader(title="Downloading Model 1/2").download(
url="https://huggingface.co/divamgupta/stable_diffusion_mps/resolve/main/sd-v1-4_fp16.tdict",
md5_checksum="9f1fc1e94821d000b811e3bb6e7686b2",
p_15 = ProgressBarDownloader(title="Downloading Model 1/2").download(
url="https://huggingface.co/divamgupta/stable_diffusion_mps/resolve/main/sd-v1-5_fp16.tdict",
md5_checksum="a36c79b8edb4b21b75e50d5834d1f4ae",
verify_ssl=False,
extract_zip=False,
)

p_14_np = ProgressBarDownloader(title="Downloading Model 2/2").download(
p_15_np = ProgressBarDownloader(title="Downloading Model 2/2").download(
url="https://huggingface.co/divamgupta/stable_diffusion_mps/resolve/main/sd-v1-5-inpainting_fp16.tdict",
md5_checksum="68303f49cca00968c39abddc20b622a6",
verify_ssl=False,
Expand Down Expand Up @@ -139,10 +139,10 @@ def process_opt(d, generator):

if d['model_id'] == 1:
model_mode = "inpaint_15"
tdict_path = p_14_np
tdict_path = p_15_np
print("sdbk mdvr 1.5_inp")
else:
tdict_path = p_14
tdict_path = p_15
print("sdbk mdvr 1.4")

if d['do_controlnet'] == True:
Expand Down Expand Up @@ -262,7 +262,7 @@ def process_opt(d, generator):

def diffusion_bee_main():

global p_14 , p_14_np
global p_15 , p_15_np
download_weights()

print("sdbk mltl Loading Model")
Expand All @@ -277,7 +277,7 @@ def callback(state="" , progress=-1):
if "__stop__" in get_input():
return "stop"

generator = StableDiffusion( ModelInterface , p_14 , model_name="sd_1x", callback=callback, debug_output_path=debug_output_path )
generator = StableDiffusion( ModelInterface , p_15 , model_name="sd_1x", callback=callback, debug_output_path=debug_output_path )


default_d = { "W" : 512 , "H" : 512, "num_imgs":1 , "ddim_steps" : 25 ,
Expand Down
7 changes: 3 additions & 4 deletions backends/stable_diffusion/stable_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def prepare_model_interface(self , sd_run=None ):


if self.current_model_name != model_name or self.current_dtype != dtype :
print("Creating model interface")
print("[SD] Creating model interface")
assert tdict_path is not None

if self.model is not None:
Expand Down Expand Up @@ -279,7 +279,7 @@ def prepare_model_interface(self , sd_run=None ):
if tdict_1 is None:
tdict_1 = TDict(tdict_path)

print("Loading LoRA weights")
print("[SD] Loading LoRA weights")
extra_weights = add_lora_ti_weights(tdict_1 , weight_additions )
self.model.load_from_state_dict(extra_weights )
self.current_weight_additions = weight_additions
Expand All @@ -292,7 +292,7 @@ def tokenize(self , prompt):
inputs = self.tokenizer.encode(prompt)

if len(inputs) >= 77:
print("Prompt is too long, stripping it ")
print("[SD] Prompt is too long, stripping it ")
inputs = inputs[:77]
if self.current_model_name == "sd_2x":
phrase = inputs + [0] * (77 - len(inputs))
Expand Down Expand Up @@ -461,7 +461,6 @@ def prepare_init_latent(self , sd_run):

def t_to_i(self, t):
i = list(self.scheduler.timesteps).index(t)
print("t 2 i " , i )
assert i >= 0
return i

Expand Down
21 changes: 20 additions & 1 deletion backends/stable_diffusion/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,27 @@ def test_lr_32():

# test_lr_1()

def test_11():

test_sd2_4()
img = sd.generate(
prompt="a tree" ,
img_height=512,
img_width=512,
seed=1,
tdict_path=None,
batch_size=1,
num_steps=5,
dtype=ModelInterface.default_float_type,
scheduler='ddim',
mode="txt2img" )

gt_p = "./test_assets/outputs/a_tree_1_ddim.png"

Image.fromarray(img['img'][0]).show()



test_11()

exit()

Expand Down
4 changes: 3 additions & 1 deletion electron_app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ pnpm-debug.log*
*.sw?

#Electron-builder output
/dist_electron
/dist_electron

build_config.json
2 changes: 1 addition & 1 deletion electron_app/afterSignHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = async function (params) {

console.log('afterSign hook triggered', params);

let appId = 'com.linerai.diffusionbee'
let appId = 'com.diffusionbee.diffusionbee'

let appPath = path.join(params.appOutDir, `${params.packager.appInfo.productFilename}.app`);
if (!fs.existsSync(appPath)) {
Expand Down
4 changes: 2 additions & 2 deletions electron_app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "DiffusionBee",
"version": "1.7.3",
"build_number": "0022",
"version": "1.7.4",
"build_number": "0023",
"website": "https://diffusionbee.com",
"description": "Diffusion Bee - Stable Diffusion App.",
"is_dev": false,
Expand Down
2 changes: 1 addition & 1 deletion electron_app/src/components/ControlNet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-->

<div v-if="inp_img" @drop.prevent="onDragFile" @dragover.prevent class="image_area" :class="{ crosshair_cur : is_inpaint }" style="height: calc(100% - 200px); border-radius: 16px; padding:5px;">
<ImageCanvas ref="inp_img_canvas" :is_inpaint="is_inpaint" :image_source="inp_img" :is_disabled="!stable_diffusion.is_input_avail" canvas_id="img2imgcan" canvas_d_id="img2imgcand" ></ImageCanvas>
<ImageCanvas ref="inp_img_canvas" :is_inpaint="is_inpaint" :image_source="inp_img" :is_disabled="!stable_diffusion.is_input_avail" canvas_id="ctrlnet" canvas_d_id="ctrlnetd" ></ImageCanvas>
</div>
<div v-else @drop.prevent="onDragFile" @dragover.prevent @click="open_input_image" class="image_area" :class="{ pointer_cursor : is_sd_active }" style="height: calc(100% - 200px); border-radius: 16px; padding:5px;">
<center>
Expand Down
4 changes: 4 additions & 0 deletions electron_app/src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
</div>
<hr> -->
<div class="l_button button_colored" style="float:right" @click="add_model" >Add New Model</div>

<h2>Custom Models</h2>
<p style="zoom:1"> Supported models : SD1.x , SD2.x - .ckpt and .safetensors </p>
<p style="zoom:0.8"> Note: If you import SD2.x 768 model, you might need to use ddim_v sampler to get better results. </p>


<!-- <br> -->
<hr>
Expand Down
6 changes: 3 additions & 3 deletions electron_app/src/components_bare/SDOptionsDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@


<b-form-select v-model="options_model_values.img_w"
:options="[64 * 4, 64 * 5, 64 * 6, 64 * 7, 64 * 8, 64 * 9, 64 * 10, 64 * 11, 64 * 12]"
:options="[64 * 4, 64 * 5, 64 * 6, 64 * 7, 64 * 8, 64 * 9, 64 * 10, 64 * 11, 64 * 12, 64*13 , 64*14]"
required></b-form-select>
</div>
<div class="options_input" style="justify-content: center;width: 75px;">
Expand All @@ -175,7 +175,7 @@
stroke-width="1.01368" stroke-linecap="round" stroke-linejoin="round" />
</svg>
<b-form-select v-model="options_model_values.img_h"
:options="[64 * 4, 64 * 5, 64 * 6, 64 * 7, 64 * 8, 64 * 9, 64 * 10, 64 * 11, 64 * 12]"
:options="[64 * 4, 64 * 5, 64 * 6, 64 * 7, 64 * 8, 64 * 9, 64 * 10, 64 * 11, 64 * 12, 64*13 , 64*14]"
required></b-form-select>
</div>
</div>
Expand Down Expand Up @@ -259,7 +259,7 @@
</svg>

<b-form-select v-model="options_model_values.selected_sampler"
:options="['ddim' , 'lmsd' , 'pndm' , 'k_euler_ancestral' , 'k_euler' ]"
:options="['ddim' , 'lmsd' , 'pndm' , 'k_euler_ancestral' , 'k_euler' , 'ddim_v' ]"
required></b-form-select>
</div>
</div>
Expand Down
15 changes: 12 additions & 3 deletions electron_app/vue.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

try {
var build_config = require('./build_config.json');
console.log(build_config + "\n\n\n\n\n")
} catch (err) {
var build_config = {}
}


module.exports = {

pluginOptions: {
Expand All @@ -8,7 +16,8 @@ module.exports = {
// Or, for multiple preload files:
// preload: { preload: 'src/preload.js', otherPreload: 'src/preload2.js' }
builderOptions: {
appId: 'com.linerai.liner',
appId: 'com.diffusionbee.diffusionbee',
artifactName: "DiffusionBee"+(build_config.build_name||"")+"-${version}.${ext}",
afterSign: "./afterSignHook.js",
"extraResources": [{
"from": process.env.BACKEND_BUILD_PATH ,
Expand All @@ -23,9 +32,9 @@ module.exports = {
"hardenedRuntime": true,
"entitlements": "build/entitlements.mac.plist",
"entitlementsInherit": "build/entitlements.mac.plist",
"minimumSystemVersion": "11.0.0",
"minimumSystemVersion": build_config.min_os_version || "11.0.0",
"extendInfo": {
"LSMinimumSystemVersion": "11.0.0"
"LSMinimumSystemVersion": build_config.min_os_version || "11.0.0"
} ,

"target": {
Expand Down

0 comments on commit 3b5e274

Please sign in to comment.