Add SwarmUI settings management and portrait generation enhancements
- Introduced new API endpoints for managing SwarmUI settings, including fetching and saving presets and age rules. - Updated the portrait generation logic to utilize the new settings structure, allowing for dynamic preset selection based on age. - Enhanced UI components to support SwarmUI settings, including localization for new strings and improved styling for settings sections. - Added tests to verify the functionality of new settings endpoints and portrait generation behavior. This commit lays the groundwork for more flexible and user-friendly portrait generation options.
This commit is contained in:
@@ -8,14 +8,10 @@ public class PortraitPromptBuilderTests
|
||||
[Fact]
|
||||
public void Build_IncludesAgeHairAndWornClothing()
|
||||
{
|
||||
var settings = new SwarmUiSettings
|
||||
{
|
||||
Positive = "School photo.",
|
||||
Avatar = new SwarmUiSettings.SwarmUiPreset { Positive = "Head and shoulders." },
|
||||
};
|
||||
var profile = SamplePreset().ToProfile(PortraitKind.Avatar);
|
||||
|
||||
var card = SampleCard();
|
||||
var (positive, _) = PortraitPromptBuilder.Build(card, settings, PortraitKind.Avatar);
|
||||
var (positive, _) = PortraitPromptBuilder.Build(card, profile, PortraitKind.Avatar);
|
||||
|
||||
Assert.Contains("age 12", positive, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("black", positive, StringComparison.OrdinalIgnoreCase);
|
||||
@@ -27,15 +23,9 @@ public class PortraitPromptBuilderTests
|
||||
[Fact]
|
||||
public void Build_FullBody_AddsFullBodyPreset()
|
||||
{
|
||||
var settings = new SwarmUiSettings
|
||||
{
|
||||
Positive = "School photo.",
|
||||
Avatar = new SwarmUiSettings.SwarmUiPreset { Positive = "Head and shoulders." },
|
||||
FullBody = new SwarmUiSettings.SwarmUiPreset { Positive = "Standing full body." },
|
||||
};
|
||||
|
||||
var (avatarPositive, _) = PortraitPromptBuilder.Build(SampleCard(), settings, PortraitKind.Avatar);
|
||||
var (fullPositive, _) = PortraitPromptBuilder.Build(SampleCard(), settings, PortraitKind.Full);
|
||||
var preset = SamplePreset();
|
||||
var (avatarPositive, _) = PortraitPromptBuilder.Build(SampleCard(), preset.ToProfile(PortraitKind.Avatar), PortraitKind.Avatar);
|
||||
var (fullPositive, _) = PortraitPromptBuilder.Build(SampleCard(), preset.ToProfile(PortraitKind.Full), PortraitKind.Full);
|
||||
|
||||
Assert.Contains("Head and shoulders.", avatarPositive, StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("Standing full body.", avatarPositive, StringComparison.Ordinal);
|
||||
@@ -45,17 +35,11 @@ public class PortraitPromptBuilderTests
|
||||
[Fact]
|
||||
public void Build_Custom_UsesPromptExtraInsteadOfPreset()
|
||||
{
|
||||
var settings = new SwarmUiSettings
|
||||
{
|
||||
Positive = "School photo.",
|
||||
Avatar = new SwarmUiSettings.SwarmUiPreset { Positive = "Head and shoulders." },
|
||||
FullBody = new SwarmUiSettings.SwarmUiPreset { Positive = "Standing full body." },
|
||||
};
|
||||
|
||||
var profile = SamplePreset().ToProfile(PortraitKind.Custom);
|
||||
const string extra = "standing in a school hallway, soft window light";
|
||||
var (customPositive, _) = PortraitPromptBuilder.Build(
|
||||
SampleCard(),
|
||||
settings,
|
||||
profile,
|
||||
PortraitKind.Custom,
|
||||
extra);
|
||||
|
||||
@@ -65,6 +49,35 @@ public class PortraitPromptBuilderTests
|
||||
Assert.DoesNotContain("Standing full body.", customPositive, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_ChildAge_UsesChildSubjectDescriptor()
|
||||
{
|
||||
var profile = SamplePreset().ToProfile(PortraitKind.Avatar);
|
||||
var child = SampleCard() with { Age = 8 };
|
||||
var (positive, _) = PortraitPromptBuilder.Build(child, profile, PortraitKind.Avatar);
|
||||
|
||||
Assert.Contains("young girl", positive, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static SwarmUiPresetDefinition SamplePreset()
|
||||
{
|
||||
var preset = SwarmUiPresetDefinition.CreateDefault();
|
||||
preset.Positive = "School photo.";
|
||||
preset.Avatar = new SwarmUiKindPreset
|
||||
{
|
||||
Width = 512,
|
||||
Height = 512,
|
||||
Positive = "Head and shoulders.",
|
||||
};
|
||||
preset.FullBody = new SwarmUiKindPreset
|
||||
{
|
||||
Width = 512,
|
||||
Height = 768,
|
||||
Positive = "Standing full body.",
|
||||
};
|
||||
return preset;
|
||||
}
|
||||
|
||||
private static PersonCardResponse SampleCard() =>
|
||||
new(
|
||||
"f0.c0",
|
||||
|
||||
Reference in New Issue
Block a user