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

Commit 7ec35e0

Browse files
committed
Filter ModelPicker by supported diffusers
1 parent 225e185 commit 7ec35e0

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

OnnxStack.UI/UserControls/ModelPickerControl.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@
5252
<Grid>
5353
<ComboBox
5454
DisplayMemberPath="Name"
55-
ItemsSource="{Binding UISettings.StableDiffusionModelSets}"
55+
ItemsSource="{Binding ModelCollectionView}"
5656
SelectedItem="{Binding SelectedModel}"
57+
IsSynchronizedWithCurrentItem="False"
5758
IsEnabled="{Binding SelectedModel.IsLoading, FallbackValue=True, TargetNullValue=True, Converter={StaticResource InverseBoolConverter}}" >
5859
</ComboBox>
5960
<TextBlock Text="-- Select Model --" Visibility="{Binding SelectedModel, Converter={StaticResource InverseNullVisibilityConverter}}" IsHitTestVisible="False" Margin="3,2" FontStyle="Italic" Opacity=".7" />

OnnxStack.UI/UserControls/ModelPickerControl.xaml.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Threading.Tasks;
1313
using System.Windows;
1414
using System.Windows.Controls;
15+
using System.Windows.Data;
1516

1617
namespace OnnxStack.UI.UserControls
1718
{
@@ -22,6 +23,7 @@ public partial class ModelPickerControl : UserControl, INotifyPropertyChanged
2223
{
2324
private readonly ILogger<ModelPickerControl> _logger;
2425
private readonly IStableDiffusionService _stableDiffusionService;
26+
private ICollectionView _modelCollectionView;
2527

2628
/// <summary>Initializes a new instance of the <see cref="ModelPickerControl" /> class.</summary>
2729
public ModelPickerControl()
@@ -46,8 +48,11 @@ public OnnxStackUIConfig UISettings
4648
set { SetValue(UISettingsProperty, value); }
4749
}
4850
public static readonly DependencyProperty UISettingsProperty =
49-
DependencyProperty.Register("UISettings", typeof(OnnxStackUIConfig), typeof(ModelPickerControl));
50-
51+
DependencyProperty.Register("UISettings", typeof(OnnxStackUIConfig), typeof(ModelPickerControl), new PropertyMetadata((d, e) =>
52+
{
53+
if (d is ModelPickerControl control && e.NewValue is OnnxStackUIConfig settings)
54+
control.InitializeModels();
55+
}));
5156

5257
/// <summary>
5358
/// Gets or sets the supported diffusers.
@@ -58,8 +63,11 @@ public List<DiffuserType> SupportedDiffusers
5863
set { SetValue(SupportedDiffusersProperty, value); }
5964
}
6065
public static readonly DependencyProperty SupportedDiffusersProperty =
61-
DependencyProperty.Register("SupportedDiffusers", typeof(List<DiffuserType>), typeof(ModelPickerControl));
62-
66+
DependencyProperty.Register("SupportedDiffusers", typeof(List<DiffuserType>), typeof(ModelPickerControl), new PropertyMetadata((d, e) =>
67+
{
68+
if (d is ModelPickerControl control && e.NewValue is List<DiffuserType> diffusers)
69+
control.ModelCollectionView?.Refresh();
70+
}));
6371

6472
/// <summary>
6573
/// Gets or sets the selected model.
@@ -73,6 +81,25 @@ public StableDiffusionModelSetViewModel SelectedModel
7381
DependencyProperty.Register("SelectedModel", typeof(StableDiffusionModelSetViewModel), typeof(ModelPickerControl));
7482

7583

84+
public ICollectionView ModelCollectionView
85+
{
86+
get { return _modelCollectionView; }
87+
set { _modelCollectionView = value; NotifyPropertyChanged(); }
88+
}
89+
90+
91+
private void InitializeModels()
92+
{
93+
ModelCollectionView = new ListCollectionView(UISettings.StableDiffusionModelSets);
94+
ModelCollectionView.Filter = (obj) =>
95+
{
96+
if (obj is not StableDiffusionModelSetViewModel viewModel)
97+
return false;
98+
99+
return viewModel.ModelSet.Diffusers.Intersect(SupportedDiffusers).Any();
100+
};
101+
}
102+
76103

77104
/// <summary>
78105
/// Loads the model.

0 commit comments

Comments
 (0)