Skip to content

Commit 852f6d6

Browse files
committed
Added new FluxTextToImage inference project type
1 parent 16f6df1 commit 852f6d6

26 files changed

Lines changed: 1023 additions & 14 deletions

StabilityMatrix.Avalonia/App.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<StyleInclude Source="Controls/Inference/PromptExpansionCard.axaml"/>
8686
<StyleInclude Source="Controls/Inference/ExtraNetworkCard.axaml"/>
8787
<StyleInclude Source="Controls/Inference/LayerDiffuseCard.axaml"/>
88+
<StyleInclude Source="Controls/Inference/UnetModelCard.axaml"/>
8889
<StyleInclude Source="Controls/Painting/PaintCanvas.axaml"/>
8990
<labs:ControlThemes/>
9091

StabilityMatrix.Avalonia/Controls/Inference/FaceDetailerCard.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@
395395
Margin="4,4,4,8"
396396
HorizontalAlignment="Stretch"
397397
Minimum="1"
398-
Maximum="65536"
398+
Maximum="16384"
399399
SmallChange="1"
400400
SpinButtonPlacementMode="Inline" />
401401

StabilityMatrix.Avalonia/Controls/Inference/PromptCard.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@
116116
Opacity="0.3" />
117117

118118
<!-- Negative Prompt -->
119-
<Grid Grid.Row="2" RowDefinitions="Auto,*">
119+
<Grid Grid.Row="2" RowDefinitions="Auto,*"
120+
IsVisible="{Binding IsNegativePromptEnabled, FallbackValue=True, TargetNullValue=True}">
120121
<StackPanel Margin="4,0,4,8" Orientation="Horizontal">
121122
<TextBlock FontSize="14" Text="Negative Prompt" />
122123
<icons:Icon

StabilityMatrix.Avalonia/Controls/Inference/SamplerCard.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194

195195
<!-- Conditioning Modules -->
196196
<Grid
197-
IsVisible="{Binding IsDimensionsEnabled}"
197+
IsVisible="{Binding EnableAddons}"
198198
Margin="0,8,0,0"
199199
ColumnDefinitions="*"
200200
RowDefinitions="*">
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<Styles
2+
xmlns="https://github.com/avaloniaui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:controls="using:StabilityMatrix.Avalonia.Controls"
5+
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
6+
xmlns:inference="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Inference"
7+
xmlns:lang="clr-namespace:StabilityMatrix.Avalonia.Languages"
8+
xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData"
9+
x:DataType="inference:UnetModelCardViewModel">
10+
<Design.PreviewWith>
11+
<Panel Width="400" Height="400">
12+
<StackPanel Width="300" VerticalAlignment="Center" Spacing="32">
13+
<controls:UnetModelCard />
14+
</StackPanel>
15+
</Panel>
16+
</Design.PreviewWith>
17+
18+
<Style Selector="controls|UnetModelCard">
19+
<Setter Property="HorizontalAlignment" Value="Stretch" />
20+
<Setter Property="Template">
21+
<ControlTemplate>
22+
<controls:Card Padding="8">
23+
<Grid
24+
ColumnDefinitions="Auto,*"
25+
RowDefinitions="*,*,*,*,*">
26+
<!-- Model -->
27+
<TextBlock
28+
Grid.Row="0"
29+
Grid.Column="0"
30+
VerticalAlignment="Center"
31+
Margin="4"
32+
Text="{x:Static lang:Resources.Label_Model}"
33+
TextAlignment="Left" />
34+
35+
<controls:BetterComboBox
36+
Grid.Row="0"
37+
Grid.Column="1"
38+
Margin="4"
39+
HorizontalAlignment="Stretch"
40+
ItemsSource="{Binding ClientManager.UnetModels}"
41+
SelectedItem="{Binding SelectedModel}"
42+
Theme="{StaticResource BetterComboBoxHybridModelTheme}"/>
43+
44+
<!-- Model -->
45+
<TextBlock
46+
Grid.Row="1"
47+
Grid.Column="0"
48+
VerticalAlignment="Center"
49+
Margin="4"
50+
Text="Precision"
51+
TextAlignment="Left" />
52+
53+
<controls:BetterComboBox
54+
Grid.Row="1"
55+
Grid.Column="1"
56+
Margin="4"
57+
HorizontalAlignment="Stretch"
58+
ItemsSource="{Binding WeightDTypes}"
59+
SelectedItem="{Binding SelectedDType}" />
60+
61+
<!-- VAE -->
62+
<TextBlock
63+
Grid.Row="2"
64+
Grid.Column="0"
65+
Margin="4"
66+
VerticalAlignment="Center"
67+
Text="{x:Static lang:Resources.Label_VAE}"
68+
TextAlignment="Left" />
69+
70+
<ui:FAComboBox
71+
Grid.Row="2"
72+
Grid.Column="1"
73+
Margin="4"
74+
HorizontalAlignment="Stretch"
75+
DisplayMemberBinding="{Binding ShortDisplayName}"
76+
IsTextSearchEnabled="True"
77+
ItemsSource="{Binding ClientManager.VaeModels}"
78+
SelectedItem="{Binding SelectedVae}" />
79+
80+
<!-- CLIP Selection 1 -->
81+
<TextBlock
82+
Grid.Row="3"
83+
Grid.Column="0"
84+
Margin="4"
85+
VerticalAlignment="Center"
86+
Text="CLIP 1"
87+
TextAlignment="Left" />
88+
89+
<ui:FAComboBox
90+
Grid.Row="3"
91+
Grid.Column="1"
92+
Margin="4"
93+
HorizontalAlignment="Stretch"
94+
DisplayMemberBinding="{Binding ShortDisplayName}"
95+
IsTextSearchEnabled="True"
96+
ItemsSource="{Binding ClientManager.ClipModels}"
97+
SelectedItem="{Binding SelectedClip1}" />
98+
99+
<!-- CLIP Selection 2 -->
100+
<TextBlock
101+
Grid.Row="4"
102+
Grid.Column="0"
103+
Margin="4"
104+
VerticalAlignment="Center"
105+
Text="CLIP 2"
106+
TextAlignment="Left" />
107+
108+
<ui:FAComboBox
109+
Grid.Row="4"
110+
Grid.Column="1"
111+
Margin="4"
112+
HorizontalAlignment="Stretch"
113+
DisplayMemberBinding="{Binding ShortDisplayName}"
114+
IsTextSearchEnabled="True"
115+
ItemsSource="{Binding ClientManager.ClipModels}"
116+
SelectedItem="{Binding SelectedClip2}" />
117+
</Grid>
118+
</controls:Card>
119+
</ControlTemplate>
120+
</Setter>
121+
</Style>
122+
</Styles>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Avalonia.Controls.Primitives;
2+
using StabilityMatrix.Core.Attributes;
3+
4+
namespace StabilityMatrix.Avalonia.Controls;
5+
6+
[Transient]
7+
public class UnetModelCard : TemplatedControl;

StabilityMatrix.Avalonia/DesignData/MockInferenceClientManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public partial class MockInferenceClientManager : ObservableObject, IInferenceCl
5353
public IObservableCollection<HybridModelFile> SamModels { get; } =
5454
new ObservableCollectionExtended<HybridModelFile>();
5555

56+
public IObservableCollection<HybridModelFile> UnetModels { get; } =
57+
new ObservableCollectionExtended<HybridModelFile>();
58+
59+
public IObservableCollection<HybridModelFile> ClipModels { get; } =
60+
new ObservableCollectionExtended<HybridModelFile>();
61+
5662
[ObservableProperty]
5763
[NotifyPropertyChangedFor(nameof(CanUserConnect))]
5864
private bool isConnected;

StabilityMatrix.Avalonia/Extensions/ComfyNodeBuilderExtensions.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,45 @@ public static void SetupEmptyLatentSource(
4747
}
4848
}
4949

50+
public static void SetupEmptySd3LatentSource(
51+
this ComfyNodeBuilder builder,
52+
int width,
53+
int height,
54+
int batchSize = 1,
55+
int? batchIndex = null
56+
)
57+
{
58+
var emptyLatent = builder.Nodes.AddTypedNode(
59+
new ComfyNodeBuilder.EmptySD3LatentImage
60+
{
61+
Name = builder.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.EmptySD3LatentImage)),
62+
BatchSize = batchSize,
63+
Height = height,
64+
Width = width
65+
}
66+
);
67+
68+
builder.Connections.Primary = emptyLatent.Output;
69+
builder.Connections.PrimarySize = new Size(width, height);
70+
71+
// If batch index is selected, add a LatentFromBatch
72+
if (batchIndex is not null)
73+
{
74+
builder.Connections.Primary = builder
75+
.Nodes.AddTypedNode(
76+
new ComfyNodeBuilder.LatentFromBatch
77+
{
78+
Name = "LatentFromBatch",
79+
Samples = builder.GetPrimaryAsLatent(),
80+
// remote expects a 0-based index, vm is 1-based
81+
BatchIndex = batchIndex.Value - 1,
82+
Length = 1
83+
}
84+
)
85+
.Output;
86+
}
87+
}
88+
5089
/// <summary>
5190
/// Setup an image as the <see cref="ComfyNodeBuilder.NodeBuilderConnections.Primary"/> connection
5291
/// </summary>

StabilityMatrix.Avalonia/Extensions/InferenceProjectTypeExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using StabilityMatrix.Core.Models.Inference;
44

55
namespace StabilityMatrix.Avalonia.Extensions;
6+
67
public static class InferenceProjectTypeExtensions
78
{
89
public static Type? ToViewModelType(this InferenceProjectType type)
@@ -14,6 +15,7 @@ public static class InferenceProjectTypeExtensions
1415
InferenceProjectType.Inpainting => null,
1516
InferenceProjectType.Upscale => typeof(InferenceImageUpscaleViewModel),
1617
InferenceProjectType.ImageToVideo => typeof(InferenceImageToVideoViewModel),
18+
InferenceProjectType.FluxTextToImage => typeof(InferenceFluxTextToImageViewModel),
1719
InferenceProjectType.Unknown => null,
1820
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
1921
};

StabilityMatrix.Avalonia/Models/InferenceProjectDocument.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public static InferenceProjectDocument FromLoadable(IJsonLoadableState loadableM
3434
InferenceTextToImageViewModel => InferenceProjectType.TextToImage,
3535
InferenceImageUpscaleViewModel => InferenceProjectType.Upscale,
3636
InferenceImageToVideoViewModel => InferenceProjectType.ImageToVideo,
37+
InferenceFluxTextToImageViewModel => InferenceProjectType.FluxTextToImage
3738
},
3839
State = loadableModel.SaveStateToJsonObject()
3940
};

0 commit comments

Comments
 (0)