Skip to content

Commit fd1da21

Browse files
authored
Merge pull request LykosAI#752 from ionite34/add-flux-text-to-image
Added new FluxTextToImage inference project type
2 parents fe741d7 + 309f88d commit fd1da21

34 files changed

+1357
-123
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
88
## v2.12.0-dev.3
99
### Added
1010
- Added Settings option "Console: History Size" to adjust the number of lines stored in the console history when running packages. Defaults to 9001 lines.
11+
#### Inference
12+
- Added new project type, "Flux Text to Image", a Flux-native workflow for text-to-image projects
13+
- Added support for the FP8 version of Flux in the regular Text to Image and Image to Image workflows via the "Use Flux Guidance" Sampler Addon
1114
#### Model Browser
1215
- Added AuraFlow & Flux base model types to the CivitAI model browser
16+
- Added CLIP/Text Encoders section to HuggingFace model browser
1317
#### Checkpoint Manager
1418
- Added "New Directory" and "Delete" options to the context menu of the tree view.
1519
- Added new toggle for drag & drop - when enabled, all selected models will now move together with the dragged model
@@ -19,6 +23,7 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
1923
- Added "unet" shared model folder for ComfyUI
2024
### Changed
2125
- The "Download Failed" message for model downloads is now persistent until dismissed
26+
- Separated the Generate button from the prompt control in Inference so it can be moved like other controls
2227
### Fixed
2328
- Fixed "The version of the native libSkiaSharp library (88.1) is incompatible with this version of SkiaSharp." error for Linux users
2429
- Fixed download links for IPAdapters in the HuggingFace model browser

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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
<!-- Set Defaults -->
2222
<Setter Property="Template">
2323
<ControlTemplate>
24-
<controls:Card Padding="12" HorizontalAlignment="{TemplateBinding HorizontalAlignment}">
24+
<controls:Card Padding="12" HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
25+
VerticalAlignment="{TemplateBinding VerticalAlignment}"
26+
VerticalContentAlignment="Stretch">
2527
<controls:Card.Styles>
2628
<Style Selector="avaloniaEdit|TextEditor">
2729
<Setter Property="Margin" Value="0,8,0,8" />
@@ -35,7 +37,8 @@
3537
</Style>
3638
</controls:Card.Styles>
3739

38-
<Grid RowDefinitions="*,16,*,16,Auto">
40+
<Grid RowDefinitions="*,16,*,16,Auto"
41+
Name="PART_RootGrid">
3942
<!-- Prompt -->
4043
<Grid ColumnDefinitions="*,Auto" RowDefinitions="Auto,*">
4144
<StackPanel
@@ -93,6 +96,7 @@
9396

9497
<avaloniaEdit:TextEditor
9598
x:Name="PromptEditor"
99+
VerticalAlignment="Stretch"
96100
Document="{Binding PromptDocument}"
97101
FontFamily="Cascadia Code,Consolas,Menlo,Monospace,DejaVu Sans Mono,monospace">
98102
<i:Interaction.Behaviors>
@@ -116,7 +120,8 @@
116120
Opacity="0.3" />
117121

118122
<!-- Negative Prompt -->
119-
<Grid Grid.Row="2" RowDefinitions="Auto,*">
123+
<Grid Grid.Row="2" RowDefinitions="Auto,*"
124+
IsVisible="{Binding IsNegativePromptEnabled, FallbackValue=True, TargetNullValue=True}">
120125
<StackPanel Margin="4,0,4,8" Orientation="Horizontal">
121126
<TextBlock FontSize="14" Text="Negative Prompt" />
122127
<icons:Icon
@@ -133,6 +138,7 @@
133138

134139
<avaloniaEdit:TextEditor
135140
x:Name="NegativePromptEditor"
141+
VerticalAlignment="Stretch"
136142
Document="{Binding NegativePromptDocument}"
137143
FontFamily="Cascadia Code,Consolas,Menlo,Monospace,DejaVu Sans Mono,monospace">
138144
<i:Interaction.Behaviors>

StabilityMatrix.Avalonia/Controls/Inference/PromptCard.axaml.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using AvaloniaEdit.Utils;
88
using StabilityMatrix.Avalonia.Helpers;
99
using StabilityMatrix.Avalonia.Models;
10+
using StabilityMatrix.Avalonia.ViewModels.Inference;
1011
using StabilityMatrix.Core.Attributes;
1112

1213
namespace StabilityMatrix.Avalonia.Controls;
@@ -19,6 +20,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
1920
{
2021
base.OnApplyTemplate(e);
2122

23+
FixGrids(e);
2224
InitializeEditors(e);
2325
}
2426

@@ -59,4 +61,25 @@ var editor in new[]
5961
}
6062
}
6163
}
64+
65+
private void FixGrids(TemplateAppliedEventArgs e)
66+
{
67+
if (DataContext is not PromptCardViewModel { IsNegativePromptEnabled: false })
68+
{
69+
return;
70+
}
71+
72+
// When negative prompt disabled, rearrange grid
73+
if (e.NameScope.Find<Grid>("PART_RootGrid") is not { } rootGrid)
74+
return;
75+
76+
// Change `*,16,*,16,Auto` to `*,16,Auto` (Remove index 2 and 3)
77+
rootGrid.RowDefinitions.RemoveRange(2, 2);
78+
79+
// Set the last children to row 2
80+
rootGrid.Children[4].SetValue(Grid.RowProperty, 2);
81+
82+
// Remove the negative prompt row and the separator row (index 2 and 3)
83+
rootGrid.Children.RemoveRange(2, 2);
84+
}
6285
}

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: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
<controls:BetterComboBox
71+
Grid.Row="2"
72+
Grid.Column="1"
73+
Margin="4"
74+
HorizontalAlignment="Stretch"
75+
IsTextSearchEnabled="True"
76+
ItemsSource="{Binding ClientManager.VaeModels}"
77+
SelectedItem="{Binding SelectedVae}"
78+
Theme="{StaticResource BetterComboBoxHybridModelTheme}"/>
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+
<controls:BetterComboBox
90+
Grid.Row="3"
91+
Grid.Column="1"
92+
Name="Clip1ComboBox"
93+
Margin="4"
94+
HorizontalAlignment="Stretch"
95+
IsTextSearchEnabled="True"
96+
ItemsSource="{Binding ClientManager.ClipModels}"
97+
SelectedItem="{Binding SelectedClip1}"
98+
Theme="{StaticResource BetterComboBoxHybridModelTheme}"/>
99+
100+
<!-- CLIP Selection 2 -->
101+
<TextBlock
102+
Grid.Row="4"
103+
Grid.Column="0"
104+
Margin="4"
105+
VerticalAlignment="Center"
106+
Text="CLIP 2"
107+
TextAlignment="Left" />
108+
109+
<controls:BetterComboBox
110+
Grid.Row="4"
111+
Grid.Column="1"
112+
Name="Clip2ComboBox"
113+
Margin="4"
114+
HorizontalAlignment="Stretch"
115+
IsTextSearchEnabled="True"
116+
ItemsSource="{Binding ClientManager.ClipModels}"
117+
SelectedItem="{Binding SelectedClip2}"
118+
Theme="{StaticResource BetterComboBoxHybridModelTheme}"/>
119+
</Grid>
120+
</controls:Card>
121+
</ControlTemplate>
122+
</Setter>
123+
</Style>
124+
</Styles>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using AsyncAwaitBestPractices;
2+
using Avalonia.Controls;
3+
using Avalonia.Controls.Primitives;
4+
using StabilityMatrix.Avalonia.ViewModels.Inference;
5+
using StabilityMatrix.Core.Attributes;
6+
using StabilityMatrix.Core.Models;
7+
8+
namespace StabilityMatrix.Avalonia.Controls;
9+
10+
[Transient]
11+
public class UnetModelCard : TemplatedControl
12+
{
13+
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
14+
{
15+
base.OnApplyTemplate(e);
16+
17+
var clip1ComboBox = e.NameScope.Find("Clip1ComboBox") as BetterComboBox;
18+
clip1ComboBox!.SelectionChanged += UpscalerComboBox_OnSelectionChanged;
19+
20+
var clip2ComboBox = e.NameScope.Find("Clip2ComboBox") as BetterComboBox;
21+
clip2ComboBox!.SelectionChanged += UpscalerComboBox_OnSelectionChanged;
22+
}
23+
24+
private void UpscalerComboBox_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
25+
{
26+
if (e.AddedItems.Count == 0)
27+
return;
28+
29+
var item = e.AddedItems[0];
30+
if (item is HybridModelFile { IsDownloadable: true })
31+
{
32+
// Reset the selection
33+
e.Handled = true;
34+
35+
if (
36+
e.RemovedItems.Count > 0
37+
&& e.RemovedItems[0] is HybridModelFile { IsDownloadable: false } removedItem
38+
)
39+
{
40+
(sender as BetterComboBox)!.SelectedItem = removedItem;
41+
}
42+
else
43+
{
44+
(sender as BetterComboBox)!.SelectedItem = null;
45+
}
46+
47+
// Show dialog to download the model
48+
(DataContext as UnetModelCardViewModel)!
49+
.RemoteDownloadCommand.ExecuteAsync(item)
50+
.SafeFireAndForget();
51+
}
52+
}
53+
}

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>

0 commit comments

Comments
 (0)