@@ -22,7 +22,6 @@ import { modelSelected } from 'features/parameters/store/actions';
22
22
import { postProcessingModelChanged , upscaleModelChanged } from 'features/parameters/store/upscaleSlice' ;
23
23
import {
24
24
zParameterCLIPEmbedModel ,
25
- zParameterModel ,
26
25
zParameterSpandrelImageToImageModel ,
27
26
zParameterT5EncoderModel ,
28
27
zParameterVAEModel ,
@@ -68,13 +67,12 @@ export const addModelsLoadedListener = (startAppListening: AppStartListening) =>
68
67
const models = modelConfigsAdapterSelectors . selectAll ( action . payload ) ;
69
68
70
69
handleMainModels ( models , state , dispatch , log ) ;
71
- // Upscale models are also "main" models, but they have their own handling
72
- handleUpscalingModels ( models , state , dispatch , log ) ;
73
70
handleRefinerModels ( models , state , dispatch , log ) ;
74
71
handleVAEModels ( models , state , dispatch , log ) ;
75
72
handleLoRAModels ( models , state , dispatch , log ) ;
76
73
handleControlAdapterModels ( models , state , dispatch , log ) ;
77
- handleSpandrelImageToImageModels ( models , state , dispatch , log ) ;
74
+ handlePostProcessingModel ( models , state , dispatch , log ) ;
75
+ handleUpscaleModel ( models , state , dispatch , log ) ;
78
76
handleIPAdapterModels ( models , state , dispatch , log ) ;
79
77
handleT5EncoderModels ( models , state , dispatch , log ) ;
80
78
handleCLIPEmbedModels ( models , state , dispatch , log ) ;
@@ -131,34 +129,6 @@ const handleMainModels: ModelHandler = (models, state, dispatch, log) => {
131
129
dispatch ( modelSelected ( firstModel ) ) ;
132
130
} ;
133
131
134
- const handleUpscalingModels : ModelHandler = ( models , state , dispatch , log ) => {
135
- const selectedUpscaleModel = state . upscale . upscaleModel ;
136
- const allUpscalingModels = models . filter ( isNonRefinerMainModelConfig ) . sort ( ( a ) => ( a . base === 'sdxl' ? - 1 : 1 ) ) ;
137
-
138
- const firstModel = allUpscalingModels [ 0 ] || null ;
139
-
140
- // If we have no models, we may need to clear the selected model
141
- if ( ! firstModel ) {
142
- // Only clear the model if we have one currently selected
143
- if ( selectedUpscaleModel !== null ) {
144
- log . debug ( { selectedUpscaleModel } , 'No upscaling models available, clearing' ) ;
145
- dispatch ( upscaleModelChanged ( null ) ) ;
146
- }
147
- return ;
148
- }
149
-
150
- // If the current model is available, we don't need to do anything
151
- if ( allUpscalingModels . some ( ( m ) => m . key === selectedUpscaleModel ?. key ) ) {
152
- return ;
153
- }
154
-
155
- log . debug (
156
- { selectedUpscaleModel, firstModel } ,
157
- 'No selected upscaling model or selected upscaling model is not available, selecting first available model'
158
- ) ;
159
- dispatch ( upscaleModelChanged ( zParameterModel . parse ( firstModel ) ) ) ;
160
- } ;
161
-
162
132
const handleRefinerModels : ModelHandler = ( models , state , dispatch , log ) => {
163
133
const selectedRefinerModel = state . params . refinerModel ;
164
134
@@ -271,7 +241,7 @@ const handleIPAdapterModels: ModelHandler = (models, state, dispatch, log) => {
271
241
} ) ;
272
242
} ;
273
243
274
- const handleSpandrelImageToImageModels : ModelHandler = ( models , state , dispatch , log ) => {
244
+ const handlePostProcessingModel : ModelHandler = ( models , state , dispatch , log ) => {
275
245
const selectedPostProcessingModel = state . upscale . postProcessingModel ;
276
246
const allSpandrelModels = models . filter ( isSpandrelImageToImageModelConfig ) ;
277
247
@@ -298,6 +268,33 @@ const handleSpandrelImageToImageModels: ModelHandler = (models, state, dispatch,
298
268
}
299
269
} ;
300
270
271
+ const handleUpscaleModel : ModelHandler = ( models , state , dispatch , log ) => {
272
+ const selectedUpscaleModel = state . upscale . upscaleModel ;
273
+ const allSpandrelModels = models . filter ( isSpandrelImageToImageModelConfig ) ;
274
+
275
+ // If the currently selected model is available, we don't need to do anything
276
+ if ( selectedUpscaleModel && allSpandrelModels . some ( ( m ) => m . key === selectedUpscaleModel . key ) ) {
277
+ return ;
278
+ }
279
+
280
+ // Else we should select the first available model
281
+ const firstModel = allSpandrelModels [ 0 ] || null ;
282
+ if ( firstModel ) {
283
+ log . debug (
284
+ { selectedUpscaleModel, firstModel } ,
285
+ 'No selected upscale model or selected upscale model is not available, selecting first available model'
286
+ ) ;
287
+ dispatch ( upscaleModelChanged ( zParameterSpandrelImageToImageModel . parse ( firstModel ) ) ) ;
288
+ return ;
289
+ }
290
+
291
+ // No available models, we should clear the selected model - but only if we have one selected
292
+ if ( selectedUpscaleModel ) {
293
+ log . debug ( { selectedUpscaleModel } , 'Selected upscale model is not available, clearing' ) ;
294
+ dispatch ( upscaleModelChanged ( null ) ) ;
295
+ }
296
+ } ;
297
+
301
298
const handleT5EncoderModels : ModelHandler = ( models , state , dispatch , log ) => {
302
299
const selectedT5EncoderModel = state . params . t5EncoderModel ;
303
300
const t5EncoderModels = models . filter ( isT5EncoderModelConfig ) ;
0 commit comments