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:
@@ -7,16 +7,16 @@ internal static class PortraitPromptBuilder
|
||||
{
|
||||
public static (string Positive, string Negative) Build(
|
||||
PersonCardResponse card,
|
||||
SwarmUiSettings settings,
|
||||
SwarmUiResolvedProfile profile,
|
||||
PortraitKind kind,
|
||||
string? promptExtra = null)
|
||||
{
|
||||
var preset = settings.PresetFor(kind);
|
||||
var kindPreset = profile.KindPreset;
|
||||
var parts = new List<string>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(settings.Positive))
|
||||
if (!string.IsNullOrWhiteSpace(profile.Positive))
|
||||
{
|
||||
parts.Add(settings.Positive.Trim());
|
||||
parts.Add(profile.Positive.Trim());
|
||||
}
|
||||
|
||||
if (kind == PortraitKind.Custom)
|
||||
@@ -26,12 +26,12 @@ internal static class PortraitPromptBuilder
|
||||
parts.Add(promptExtra.Trim());
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(preset.Positive))
|
||||
else if (!string.IsNullOrWhiteSpace(kindPreset.Positive))
|
||||
{
|
||||
parts.Add(preset.Positive.Trim());
|
||||
parts.Add(kindPreset.Positive.Trim());
|
||||
}
|
||||
|
||||
parts.Add(card.Female ? "A young woman" : "A young man");
|
||||
parts.Add(DescribeSubject(card));
|
||||
parts.Add($"age {card.Age}");
|
||||
|
||||
foreach (var row in card.Body)
|
||||
@@ -53,7 +53,25 @@ internal static class PortraitPromptBuilder
|
||||
}
|
||||
|
||||
var positive = string.Join(", ", parts.Where(part => part.Length > 0));
|
||||
var negative = settings.Negative?.Trim() ?? string.Empty;
|
||||
var negative = SwarmUiLoraFormatter.AppendLoraTags(
|
||||
profile.Negative.Trim(),
|
||||
profile.NegativeLoras);
|
||||
|
||||
return (positive, negative);
|
||||
}
|
||||
|
||||
private static string DescribeSubject(PersonCardResponse card)
|
||||
{
|
||||
if (card.Age <= 11)
|
||||
{
|
||||
return card.Female ? "A young girl" : "A young boy";
|
||||
}
|
||||
|
||||
if (card.Age <= 17)
|
||||
{
|
||||
return card.Female ? "A teenage girl" : "A teenage boy";
|
||||
}
|
||||
|
||||
return card.Female ? "A young woman" : "A young man";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user