Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit 5ad1170

Browse files
committed
Move model templates to ModelFactory
1 parent 4a10b8c commit 5ad1170

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

OnnxStack.UI/Dialogs/AddModelDialog.xaml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,8 @@
2020

2121
<StackPanel >
2222
<TextBlock Text="Model Type"/>
23-
<ComboBox ItemsSource="{Binding ModelTemplates}" SelectedItem="{Binding ModelTemplate}" DisplayMemberPath="PipelineType" >
24-
<ComboBox.ItemContainerStyle>
25-
<Style TargetType="{x:Type ComboBoxItem}" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
26-
<Setter Property="Visibility" Value="Visible" />
27-
<Style.Triggers>
28-
<DataTrigger Binding="{Binding Category}" Value="Upscaler">
29-
<Setter Property="Visibility" Value="Collapsed"/>
30-
</DataTrigger>
31-
<DataTrigger Binding="{Binding IsUserTemplate}" Value="True">
32-
<Setter Property="Visibility" Value="Collapsed"/>
33-
</DataTrigger>
34-
</Style.Triggers>
35-
36-
</Style>
37-
</ComboBox.ItemContainerStyle>
23+
<ComboBox ItemsSource="{Binding ModelTemplates}" SelectedItem="{Binding ModelTemplate}" DisplayMemberPath="Name" >
24+
3825
</ComboBox>
3926
</StackPanel>
4027

OnnxStack.UI/Dialogs/AddModelDialog.xaml.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,11 @@ public AddModelDialog(OnnxStackUIConfig settings, IModelFactory modelFactory, IL
3737
_modelFactory = modelFactory;
3838
SaveCommand = new AsyncRelayCommand(Save, CanExecuteSave);
3939
CancelCommand = new AsyncRelayCommand(Cancel);
40-
ModelTemplates = GetModelTemplates().ToList();
40+
ModelTemplates = new List<StableDiffusionModelTemplate>( _modelFactory.GetStableDiffusionModelTemplates());
4141
InvalidOptions = _settings.StableDiffusionModelSets.Select(x => x.Name.ToLower()).ToList();
4242
InitializeComponent();
4343
}
4444

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-
5145
public AsyncRelayCommand SaveCommand { get; }
5246
public AsyncRelayCommand CancelCommand { get; }
5347
public ObservableCollection<ValidationResult> ValidationResults { get; set; } = new ObservableCollection<ValidationResult>();
@@ -105,6 +99,8 @@ private void CreateModelSet()
10599
{
106100
_modelSetResult = null;
107101
ValidationResults.Clear();
102+
if (_modelTemplate is null)
103+
return;
108104
if (string.IsNullOrEmpty(_modelFolder))
109105
return;
110106

OnnxStack.UI/Dialogs/AddUpscaleModelDialog.xaml.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,11 @@ public AddUpscaleModelDialog(OnnxStackUIConfig settings, IModelFactory modelFact
3636
_modelFactory = modelFactory;
3737
SaveCommand = new AsyncRelayCommand(Save, CanExecuteSave);
3838
CancelCommand = new AsyncRelayCommand(Cancel);
39-
ModelTemplates = GetModelTemplates().ToList();
39+
ModelTemplates = new List<UpscaleModelTemplate>(_modelFactory.GetUpscaleModelTemplates());
4040
InvalidOptions = _settings.UpscaleModelSets.Select(x => x.Name.ToLower()).ToList();
4141
InitializeComponent();
4242
}
4343

44-
private IEnumerable<UpscaleModelTemplate> GetModelTemplates()
45-
{
46-
yield return new UpscaleModelTemplate("Upscale 2x", 2, 512);
47-
yield return new UpscaleModelTemplate("Upscale 4x", 4, 512);
48-
}
4944

5045
public AsyncRelayCommand SaveCommand { get; }
5146
public AsyncRelayCommand CancelCommand { get; }

OnnxStack.UI/Services/IModelFactory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using OnnxStack.StableDiffusion.Config;
2+
using System.Collections.Generic;
23

34
namespace OnnxStack.UI.Services
45
{
56
public interface IModelFactory
67
{
8+
IEnumerable<UpscaleModelTemplate> GetUpscaleModelTemplates();
9+
IEnumerable<StableDiffusionModelTemplate> GetStableDiffusionModelTemplates();
10+
711
UpscaleModelSet CreateUpscaleModelSet(string name, string filename, UpscaleModelTemplate modelTemplate);
812
StableDiffusionModelSet CreateStableDiffusionModelSet(string name, string folder, StableDiffusionModelTemplate modelTemplate);
913
}

OnnxStack.UI/Services/ModelFactory.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ public ModelFactory(OnnxStackUIConfig settings)
2222
_defaultTokenizerPath = defaultTokenizerPath;
2323
}
2424

25+
public IEnumerable<UpscaleModelTemplate> GetUpscaleModelTemplates()
26+
{
27+
yield return new UpscaleModelTemplate("Upscale 2x", 2, 512);
28+
yield return new UpscaleModelTemplate("Upscale 4x", 4, 512);
29+
}
30+
31+
32+
public IEnumerable<StableDiffusionModelTemplate> GetStableDiffusionModelTemplates()
33+
{
34+
yield return new StableDiffusionModelTemplate("SD", DiffuserPipelineType.StableDiffusion, ModelType.Base, 512, DiffuserType.TextToImage, DiffuserType.ImageToImage, DiffuserType.ImageInpaintLegacy);
35+
yield return new StableDiffusionModelTemplate("SD-Inpaint", DiffuserPipelineType.StableDiffusion, ModelType.Base, 512, DiffuserType.ImageInpaint);
36+
37+
yield return new StableDiffusionModelTemplate("SDXL", DiffuserPipelineType.StableDiffusionXL, ModelType.Base, 1024, DiffuserType.TextToImage, DiffuserType.ImageToImage, DiffuserType.ImageInpaintLegacy);
38+
yield return new StableDiffusionModelTemplate("SDXL-Inpaint", DiffuserPipelineType.StableDiffusionXL, ModelType.Base, 1024, DiffuserType.ImageInpaint);
39+
yield return new StableDiffusionModelTemplate("SDXL-Refiner", DiffuserPipelineType.StableDiffusionXL, ModelType.Refiner, 1024, DiffuserType.ImageToImage, DiffuserType.ImageInpaintLegacy);
40+
yield return new StableDiffusionModelTemplate("SDXL-Turbo", DiffuserPipelineType.StableDiffusionXL, ModelType.Base, 512, DiffuserType.TextToImage, DiffuserType.ImageToImage, DiffuserType.ImageInpaintLegacy);
41+
42+
yield return new StableDiffusionModelTemplate("LCM", DiffuserPipelineType.LatentConsistency, ModelType.Base, 512, DiffuserType.TextToImage, DiffuserType.ImageToImage, DiffuserType.ImageInpaintLegacy);
43+
yield return new StableDiffusionModelTemplate("LCM-SDXL", DiffuserPipelineType.LatentConsistencyXL, ModelType.Base, 1024, DiffuserType.TextToImage, DiffuserType.ImageToImage, DiffuserType.ImageInpaintLegacy);
44+
45+
yield return new StableDiffusionModelTemplate("InstaFlow", DiffuserPipelineType.InstaFlow, ModelType.Base, 512, DiffuserType.TextToImage);
46+
}
47+
48+
2549
public StableDiffusionModelSet CreateStableDiffusionModelSet(string name, string folder, StableDiffusionModelTemplate modelTemplate)
2650
{
2751
var modelSet = new StableDiffusionModelSet

0 commit comments

Comments
 (0)