forked from extern/easydiffusion
Download known controlnet models if selected; Auto-pick the recommended controlnet model when a filter is selected
This commit is contained in:
parent
eba7bab15e
commit
ae34c9e84b
@ -18,7 +18,7 @@ os_name = platform.system()
|
||||
modules_to_check = {
|
||||
"torch": ("1.11.0", "1.13.1", "2.0.0"),
|
||||
"torchvision": ("0.12.0", "0.14.1", "0.15.1"),
|
||||
"sdkit": "1.0.154",
|
||||
"sdkit": "1.0.155",
|
||||
"stable-diffusion-sdkit": "2.1.4",
|
||||
"rich": "12.6.0",
|
||||
"uvicorn": "0.19.0",
|
||||
|
@ -186,6 +186,12 @@ def resolve_model_paths(models_data: ModelsData):
|
||||
continue
|
||||
if model_type == "codeformer":
|
||||
download_if_necessary("codeformer", "codeformer.pth", "codeformer-0.1.0")
|
||||
elif model_type == "controlnet":
|
||||
model_id = model_paths[model_type]
|
||||
model_info = get_model_info_from_db(model_type=model_type, model_id=model_id)
|
||||
if model_info:
|
||||
filename = model_info.get("url", "").split("/")[-1]
|
||||
download_if_necessary("controlnet", filename, model_id, skip_if_others_exist=False)
|
||||
|
||||
model_paths[model_type] = resolve_model_to_use(model_paths[model_type], model_type=model_type)
|
||||
|
||||
@ -209,17 +215,17 @@ def download_default_models_if_necessary():
|
||||
print(model_type, "model(s) found.")
|
||||
|
||||
|
||||
def download_if_necessary(model_type: str, file_name: str, model_id: str):
|
||||
def download_if_necessary(model_type: str, file_name: str, model_id: str, skip_if_others_exist=True):
|
||||
model_path = os.path.join(app.MODELS_DIR, model_type, file_name)
|
||||
expected_hash = get_model_info_from_db(model_type=model_type, model_id=model_id)["quick_hash"]
|
||||
|
||||
other_models_exist = any_model_exists(model_type)
|
||||
other_models_exist = any_model_exists(model_type) and skip_if_others_exist
|
||||
known_model_exists = os.path.exists(model_path)
|
||||
known_model_is_corrupt = known_model_exists and hash_file_quick(model_path) != expected_hash
|
||||
|
||||
if known_model_is_corrupt or (not other_models_exist and not known_model_exists):
|
||||
print("> download", model_type, model_id)
|
||||
download_model(model_type, model_id, download_base_dir=app.MODELS_DIR)
|
||||
download_model(model_type, model_id, download_base_dir=app.MODELS_DIR, download_config_if_available=False)
|
||||
|
||||
|
||||
def migrate_legacy_model_location():
|
||||
@ -296,7 +302,20 @@ def getModels(scan_for_malicious: bool = True):
|
||||
"lora": [],
|
||||
"codeformer": [{"codeformer": "CodeFormer"}],
|
||||
"embeddings": [],
|
||||
"controlnet": [],
|
||||
"controlnet": [
|
||||
{"control_v11p_sd15_canny": "Canny (*)"},
|
||||
{"control_v11p_sd15_openpose": "OpenPose (*)"},
|
||||
{"control_v11p_sd15_normalbae": "Normal BAE (*)"},
|
||||
{"control_v11f1p_sd15_depth": "Depth (*)"},
|
||||
{"control_v11p_sd15_scribble": "Scribble"},
|
||||
{"control_v11p_sd15_softedge": "Soft Edge"},
|
||||
{"control_v11p_sd15_inpaint": "Inpaint"},
|
||||
{"control_v11p_sd15_lineart": "Line Art"},
|
||||
{"control_v11p_sd15s2_lineart_anime": "Line Art Anime"},
|
||||
{"control_v11p_sd15_mlsd": "Straight Lines"},
|
||||
{"control_v11p_sd15_seg": "Segment"},
|
||||
{"control_v11e_sd15_shuffle": "Shuffle"},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@
|
||||
<td><label for="convert_to_tensorrt">Enable TensorRT:</label></td>
|
||||
<td class="diffusers-restart-needed">
|
||||
<input id="convert_to_tensorrt" name="convert_to_tensorrt" type="checkbox">
|
||||
<label><small>Takes upto 20 mins the first time</small></label>
|
||||
<!-- <label><small>Takes upto 20 mins the first time</small></label> -->
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="pl-5 displayNone" id="clip_skip_config">
|
||||
@ -211,6 +211,8 @@
|
||||
</select>
|
||||
<br/>
|
||||
<label for="controlnet_model"><small>Model:</small></label> <input id="controlnet_model" type="text" spellcheck="false" autocomplete="off" class="model-filter" data-path="" />
|
||||
<br/>
|
||||
<label><small>Will download the necessary models, the first time.</small></label>
|
||||
</div>
|
||||
</td></tr>
|
||||
<tr class="pl-5"><td><label for="vae_model">Custom VAE:</label></td><td>
|
||||
|
@ -119,7 +119,7 @@ let codeformerFidelityField = document.querySelector("#codeformer_fidelity")
|
||||
let stableDiffusionModelField = new ModelDropdown(document.querySelector("#stable_diffusion_model"), "stable-diffusion")
|
||||
let clipSkipField = document.querySelector("#clip_skip")
|
||||
let tilingField = document.querySelector("#tiling")
|
||||
let controlnetModelField = new ModelDropdown(document.querySelector("#controlnet_model"), "controlnet", "None")
|
||||
let controlnetModelField = new ModelDropdown(document.querySelector("#controlnet_model"), "controlnet", "None", false)
|
||||
let vaeModelField = new ModelDropdown(document.querySelector("#vae_model"), "vae", "None")
|
||||
let hypernetworkModelField = new ModelDropdown(document.querySelector("#hypernetwork_model"), "hypernetwork", "None")
|
||||
let hypernetworkStrengthSlider = document.querySelector("#hypernetwork_strength_slider")
|
||||
@ -1880,6 +1880,37 @@ controlImagePreview.addEventListener("load", onControlnetModelChange)
|
||||
controlImagePreview.addEventListener("unload", onControlnetModelChange)
|
||||
onControlnetModelChange()
|
||||
|
||||
function onControlImageFilterChange() {
|
||||
let filterId = controlImageFilterField.value
|
||||
if (filterId.includes("openpose")) {
|
||||
controlnetModelField.value = "control_v11p_sd15_openpose"
|
||||
} else if (filterId === "canny") {
|
||||
controlnetModelField.value = "control_v11p_sd15_canny"
|
||||
} else if (filterId === "mlsd") {
|
||||
controlnetModelField.value = "control_v11p_sd15_mlsd"
|
||||
} else if (filterId === "mlsd") {
|
||||
controlnetModelField.value = "control_v11p_sd15_mlsd"
|
||||
} else if (filterId.includes("scribble")) {
|
||||
controlnetModelField.value = "control_v11p_sd15_scribble"
|
||||
} else if (filterId.includes("softedge")) {
|
||||
controlnetModelField.value = "control_v11p_sd15_softedge"
|
||||
} else if (filterId === "normal_bae") {
|
||||
controlnetModelField.value = "control_v11p_sd15_normalbae"
|
||||
} else if (filterId.includes("depth")) {
|
||||
controlnetModelField.value = "control_v11f1p_sd15_depth"
|
||||
} else if (filterId === "lineart_anime") {
|
||||
controlnetModelField.value = "control_v11p_sd15s2_lineart_anime"
|
||||
} else if (filterId.includes("lineart")) {
|
||||
controlnetModelField.value = "control_v11p_sd15_lineart"
|
||||
} else if (filterId === "shuffle") {
|
||||
controlnetModelField.value = "control_v11e_sd15_shuffle"
|
||||
} else if (filterId === "segment") {
|
||||
controlnetModelField.value = "control_v11p_sd15_seg"
|
||||
}
|
||||
}
|
||||
controlImageFilterField.addEventListener("change", onControlImageFilterChange)
|
||||
onControlImageFilterChange()
|
||||
|
||||
upscaleModelField.disabled = !useUpscalingField.checked
|
||||
upscaleAmountField.disabled = !useUpscalingField.checked
|
||||
useUpscalingField.addEventListener("change", function(e) {
|
||||
|
Loading…
Reference in New Issue
Block a user