add Auto Fill Model from metadata

auto_fill_settings
Abdullah Alfaraj 2023-01-02 09:28:15 +03:00
parent f21d05ae17
commit 8c71798693
2 changed files with 43 additions and 1 deletions

View File

@ -192,6 +192,40 @@ function autoFillInSampler(sampler_name){
}
////// End Samplers//////////
////// Start Models//////////
function getModelElementByHash(model_hash){
try{
//assume the model_hash is valid
//return the first model menu item element with model_hash
const model_element = [...document.getElementsByClassName('mModelMenuItem')].filter(e => e.dataset.model_hash == model_hash)[0]
return model_element
}catch(e){
console.warn(`Model '${model_hash}' not found ${e}`)
}
}
function getSelectedModelHash(){
//return the hash of the first selected model menu item
return [...document.getElementsByClassName('mModelMenuItem')].filter(e => e.selected == true)[0].dataset.model_hash
}
function selectModelUi(model_hash){
model_element = getModelElementByHash(model_hash)
model_element.selected = true
}
function autoFillInModel(model_hash){
// unCheckAllSamplers()
model_element = getModelElementByHash(model_hash)
selectModelUi(model_hash)
// model_element.
const model_title = model_element.dataset.model_title
return model_title
}
////// End Models//////////
module.exports = {
getPrompt,
autoFillInPrompt,
@ -209,6 +243,7 @@ module.exports = {
setHiResFixs,
autoFillInSliderUi,
getCheckedSamplerName,
autoFillInSampler
autoFillInSampler,
autoFillInModel
}

View File

@ -180,6 +180,8 @@ async function refreshUI(){
await refreshModels()
await updateVersionUI()
}
async function refreshModels () {
try{
@ -191,7 +193,10 @@ async function refreshModels () {
for (let model of g_models) {
console.log(model.title)
const menu_item_element = document.createElement('sp-menu-item')
menu_item_element.className = "mModelMenuItem"
menu_item_element.innerHTML = model.title
menu_item_element.dataset.model_hash = model.hash
menu_item_element.dataset.model_title = model.title
document.getElementById('mModelsMenu').appendChild(menu_item_element)
}
}catch(e){
@ -308,6 +313,8 @@ function autoFillInSettings(metadata_json){
// = metadata_json['Denoising strength']
html_manip.autoFillInDenoisingStrength(metadata_json['Denoising strength'])
model_title = html_manip.autoFillInModel(metadata_json["Model hash"])
sdapi.requestSwapModel(model_title)
const [width,height] = metadata_json['Size'].split('x')
console.log("width, height: ",width, height)