11using Microsoft . Extensions . Logging ;
22using OnnxStack . StableDiffusion . Config ;
3+ using OnnxStack . StableDiffusion . Enums ;
34using OnnxStack . UI . Commands ;
45using OnnxStack . UI . Models ;
56using OnnxStack . UI . Services ;
6- using OnnxStack . UI . Views ;
7- using System ;
87using System . Collections . Generic ;
98using System . Collections . ObjectModel ;
109using System . ComponentModel ;
@@ -28,34 +27,33 @@ public partial class AddModelDialog : Window, INotifyPropertyChanged
2827 private string _modelName ;
2928 private IModelFactory _modelFactory ;
3029 private OnnxStackUIConfig _settings ;
31- private ModelTemplateViewModel _modelTemplate ;
30+ private StableDiffusionModelTemplate _modelTemplate ;
3231 private StableDiffusionModelSet _modelSetResult ;
3332
3433 public AddModelDialog ( OnnxStackUIConfig settings , IModelFactory modelFactory , ILogger < AddModelDialog > logger )
3534 {
3635 _logger = logger ;
3736 _settings = settings ;
3837 _modelFactory = modelFactory ;
39- WindowCloseCommand = new AsyncRelayCommand ( WindowClose ) ;
40- WindowRestoreCommand = new AsyncRelayCommand ( WindowRestore ) ;
41- WindowMinimizeCommand = new AsyncRelayCommand ( WindowMinimize ) ;
42- WindowMaximizeCommand = new AsyncRelayCommand ( WindowMaximize ) ;
4338 SaveCommand = new AsyncRelayCommand ( Save , CanExecuteSave ) ;
4439 CancelCommand = new AsyncRelayCommand ( Cancel ) ;
45- ModelTemplates = _settings . Templates . Where ( x => ! x . IsUserTemplate ) . ToList ( ) ;
46- InvalidOptions = _settings . Templates . Where ( x => x . IsUserTemplate ) . Select ( x => x . Name . ToLower ( ) ) . ToList ( ) ;
40+ ModelTemplates = GetModelTemplates ( ) . ToList ( ) ;
41+ InvalidOptions = _settings . StableDiffusionModelSets . Select ( x => x . Name . ToLower ( ) ) . ToList ( ) ;
4742 InitializeComponent ( ) ;
4843 }
49- public AsyncRelayCommand WindowMinimizeCommand { get ; }
50- public AsyncRelayCommand WindowRestoreCommand { get ; }
51- public AsyncRelayCommand WindowMaximizeCommand { get ; }
52- public AsyncRelayCommand WindowCloseCommand { get ; }
44+
45+ private IEnumerable < StableDiffusionModelTemplate > GetModelTemplates ( )
46+ {
47+ yield return new StableDiffusionModelTemplate ( "StableDiffusion" , DiffuserPipelineType . StableDiffusion , ModelType . Base , 512 , DiffuserType . TextToImage , DiffuserType . ImageToImage , DiffuserType . ImageInpaintLegacy ) ;
48+ yield return new StableDiffusionModelTemplate ( "SDXL" , DiffuserPipelineType . StableDiffusionXL , ModelType . Base , 1024 , DiffuserType . TextToImage , DiffuserType . ImageToImage , DiffuserType . ImageInpaintLegacy ) ;
49+ }
50+
5351 public AsyncRelayCommand SaveCommand { get ; }
5452 public AsyncRelayCommand CancelCommand { get ; }
5553 public ObservableCollection < ValidationResult > ValidationResults { get ; set ; } = new ObservableCollection < ValidationResult > ( ) ;
56- public List < ModelTemplateViewModel > ModelTemplates { get ; set ; }
54+ public List < StableDiffusionModelTemplate > ModelTemplates { get ; set ; }
5755
58- public ModelTemplateViewModel ModelTemplate
56+ public StableDiffusionModelTemplate ModelTemplate
5957 {
6058 get { return _modelTemplate ; }
6159 set { _modelTemplate = value ; NotifyPropertyChanged ( ) ; CreateModelSet ( ) ; }
@@ -78,7 +76,7 @@ public string ModelFolder
7876 set
7977 {
8078 _modelFolder = value ;
81- if ( _modelTemplate is not null && ! _modelTemplate . IsUserTemplate )
79+ if ( _modelTemplate is not null )
8280 _modelName = string . IsNullOrEmpty ( _modelFolder )
8381 ? string . Empty
8482 : Path . GetFileName ( _modelFolder ) ;
@@ -94,31 +92,11 @@ public StableDiffusionModelSet ModelSetResult
9492 get { return _modelSetResult ; }
9593 }
9694
97- private bool _enableTemplateSelection = true ;
9895
99- public bool EnableTemplateSelection
100- {
101- get { return _enableTemplateSelection ; }
102- set { _enableTemplateSelection = value ; NotifyPropertyChanged ( ) ; }
103- }
104-
105- private bool _enableNameSelection = true ;
106- public bool EnableNameSelection
107- {
108- get { return _enableNameSelection ; }
109- set { _enableNameSelection = value ; NotifyPropertyChanged ( ) ; }
110- }
11196
11297
113- public bool ShowDialog ( ModelTemplateViewModel selectedTemplate = null )
98+ public new bool ShowDialog ( )
11499 {
115- if ( selectedTemplate is not null )
116- {
117- EnableNameSelection = ! selectedTemplate . IsUserTemplate ;
118- EnableTemplateSelection = false ;
119- ModelTemplate = selectedTemplate ;
120- ModelName = selectedTemplate . IsUserTemplate ? selectedTemplate . Name : string . Empty ;
121- }
122100 return base . ShowDialog ( ) ?? false ;
123101 }
124102
@@ -130,12 +108,10 @@ private void CreateModelSet()
130108 if ( string . IsNullOrEmpty ( _modelFolder ) )
131109 return ;
132110
133- _modelSetResult = _modelFactory . CreateStableDiffusionModelSet ( ModelName . Trim ( ) , ModelFolder , _modelTemplate . StableDiffusionTemplate ) ;
111+ _modelSetResult = _modelFactory . CreateStableDiffusionModelSet ( ModelName . Trim ( ) , ModelFolder , _modelTemplate ) ;
134112
135113 // Validate
136- if ( _enableNameSelection )
137- ValidationResults . Add ( new ValidationResult ( "Name" , ! InvalidOptions . Contains ( _modelName . ToLower ( ) ) && _modelName . Length > 2 && _modelName . Length < 50 ) ) ;
138-
114+ ValidationResults . Add ( new ValidationResult ( "Name" , ! InvalidOptions . Contains ( _modelName . ToLower ( ) ) && _modelName . Length > 2 && _modelName . Length < 50 ) ) ;
139115 foreach ( var validationResult in _modelSetResult . ModelConfigurations . Select ( x => new ValidationResult ( x . Type . ToString ( ) , File . Exists ( x . OnnxModelPath ) ) ) )
140116 {
141117 ValidationResults . Add ( validationResult ) ;
@@ -168,41 +144,6 @@ private Task Cancel()
168144 return Task . CompletedTask ;
169145 }
170146
171- #region BaseWindow
172-
173- private Task WindowClose ( )
174- {
175- Close ( ) ;
176- return Task . CompletedTask ;
177- }
178-
179- private Task WindowRestore ( )
180- {
181- if ( WindowState == WindowState . Maximized )
182- WindowState = WindowState . Normal ;
183- else
184- WindowState = WindowState . Maximized ;
185- return Task . CompletedTask ;
186- }
187-
188- private Task WindowMinimize ( )
189- {
190- WindowState = WindowState . Minimized ;
191- return Task . CompletedTask ;
192- }
193-
194- private Task WindowMaximize ( )
195- {
196- WindowState = WindowState . Maximized ;
197- return Task . CompletedTask ;
198- }
199-
200- private void OnContentRendered ( object sender , EventArgs e )
201- {
202- InvalidateVisual ( ) ;
203- }
204- #endregion
205-
206147 #region INotifyPropertyChanged
207148 public event PropertyChangedEventHandler PropertyChanged ;
208149 public void NotifyPropertyChanged ( [ CallerMemberName ] string property = "" )
0 commit comments