import{isEmpty}from"../../base/helpers.mjs";import{FormView}from"../../view/forms/base.mjs";import{Controller}from"../base.mjs";import{NumberInputView,FloatInputView,CheckboxInputView}from"../../view/forms/input.mjs";import{SchedulerInputView,MultiDiffusionSchedulerInputView}from"../common/model-manager.mjs";let defaultGuidanceScale=7.5,defaultInferenceSteps=50;class TweaksForm extends FormView{static autoSubmit=!0;static collapseFieldSets=!0;static fieldSets={Tweaks:{guidanceScale:{label:"Guidance Scale",class:FloatInputView,config:{min:0,max:100,value:defaultGuidanceScale,step:.1,tooltip:"How closely to follow the text prompt; high values result in high-contrast images closely adhering to your text, low values result in low-contrast images with more randomness."}},inferenceSteps:{label:"Inference Steps",class:NumberInputView,config:{min:5,max:250,value:defaultInferenceSteps,tooltip:"How many steps to take during primary inference, larger values take longer to process but can produce better results."}},scheduler:{label:"Scheduler",class:SchedulerInputView},multiScheduler:{label:"Multi-Diffusion Scheduler",class:MultiDiffusionSchedulerInputView}}}}class TweaksController extends Controller{getState(){return{tweaks:this.tweaksForm.values}}setState(e){isEmpty(e.tweaks)||this.tweaksForm.setValues(e.tweaks).then((()=>this.tweaksForm.submit()))}getDefaultState(){return{tweaks:{guidanceScale:defaultGuidanceScale,inferenceSteps:defaultInferenceSteps,scheduler:null,multiScheduler:null}}}async initialize(){defaultGuidanceScale=this.application.config.model.invocation.guidanceScale,defaultInferenceSteps=this.application.config.model.invocation.inferenceSteps,this.tweaksForm=new TweaksForm(this.config),this.tweaksForm.onSubmit((async e=>{this.engine.guidanceScale=e.guidanceScale,this.engine.inferenceSteps=e.inferenceSteps,this.engine.scheduler=e.scheduler,this.engine.multiScheduler=e.multiScheduler})),this.subscribe("modelPickerChange",(e=>{if(!isEmpty(e)){let t=e.defaultConfiguration,i={};isEmpty(t.guidance_scale)||(i.guidanceScale=t.guidance_scale),isEmpty(t.inference_steps)||(i.inferenceSteps=t.inference_steps),isEmpty(t.scheduler)||(i.scheduler=t.scheduler),isEmpty(t.multi_scheduler)||(i.multiScheduler=t.multi_scheduler),isEmpty(i)||this.tweaksForm.setValues(i)}})),this.application.sidebar.addChild(this.tweaksForm)}}export{TweaksController as SidebarController};
