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

Commit bf58953

Browse files
committed
A few themes added
1 parent 1468eb0 commit bf58953

File tree

15 files changed

+207
-12260
lines changed

15 files changed

+207
-12260
lines changed

OnnxStack.WebUI/Hubs/StableDiffusionHub.cs

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ public override async Task OnDisconnectedAsync(Exception exception)
6262
/// <param name="cancellationToken">The cancellation token.</param>
6363
/// <returns></returns>
6464
[HubMethodName("ExecuteTextToImage")]
65-
public async IAsyncEnumerable<TextToImageResult> OnExecuteTextToImage(TextToImageOptions options, [EnumeratorCancellation] CancellationToken cancellationToken)
65+
public async IAsyncEnumerable<TextToImageResult> OnExecuteTextToImage(PromptOptions promptOptions, SchedulerOptions schedulerOptions, [EnumeratorCancellation] CancellationToken cancellationToken)
6666
{
6767
_logger.Log(LogLevel.Information, "[OnExecuteTextToImage] - New request received, Connection: {0}", Context.ConnectionId);
6868
var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(Context.ConnectionAborted, cancellationToken);
6969

7070
// TODO: Add support for multiple results
71-
var result = await GenerateTextToImageResult(options, cancellationTokenSource.Token);
71+
var result = await GenerateTextToImageResult(promptOptions, schedulerOptions, cancellationTokenSource.Token);
7272
if (result is null)
7373
yield break;
7474

@@ -82,50 +82,21 @@ public async IAsyncEnumerable<TextToImageResult> OnExecuteTextToImage(TextToImag
8282
/// <param name="options">The options.</param>
8383
/// <param name="cancellationToken">The cancellation token.</param>
8484
/// <returns></returns>
85-
private async Task<TextToImageResult> GenerateTextToImageResult(TextToImageOptions options, CancellationToken cancellationToken)
85+
private async Task<TextToImageResult> GenerateTextToImageResult(PromptOptions promptOptions, SchedulerOptions schedulerOptions, CancellationToken cancellationToken)
8686
{
8787
var timestamp = Stopwatch.GetTimestamp();
88-
options.Seed = GenerateSeed(options.Seed);
89-
var promptOptions = new PromptOptions
90-
{
91-
Prompt = options.Prompt,
92-
NegativePrompt = options.NegativePrompt,
93-
SchedulerType = options.SchedulerType
94-
};
95-
96-
var schedulerOptions = new SchedulerOptions
97-
{
98-
Seed = options.Seed,
99-
Width = options.Width,
100-
Height = options.Height,
101-
InferenceSteps = options.InferenceSteps,
102-
GuidanceScale = options.GuidanceScale,
103-
AlphaTransformType = options.AlphaTransformType,
104-
BetaEnd = options.BetaEnd,
105-
BetaSchedule = options.BetaSchedule,
106-
BetaStart = options.BetaStart,
107-
ClipSample = options.ClipSample,
108-
ClipSampleRange = options.ClipSampleRange,
109-
MaximumBeta = options.MaximumBeta,
110-
PredictionType = options.PredictionType,
111-
StepsOffset = options.StepsOffset,
112-
TimestepSpacing = options.TimestepSpacing,
113-
Thresholding = options.Thresholding,
114-
TrainTimesteps = options.TrainTimesteps,
115-
UseKarrasSigmas = options.UseKarrasSigmas,
116-
VarianceType = options.VarianceType
117-
};
118-
88+
schedulerOptions.Seed = GenerateSeed(schedulerOptions.Seed);
11989

90+
var blueprint = new ImageBlueprint(promptOptions, schedulerOptions);
12091
var fileInfo = CreateFileInfo(promptOptions, schedulerOptions);
121-
if (!await SaveOptionsFile(fileInfo, options))
92+
if (!await SaveBlueprintFile(fileInfo, blueprint))
12293
return null;
12394

12495
if (!await RunStableDiffusion(promptOptions, schedulerOptions, fileInfo, cancellationToken))
12596
return null;
12697

12798
var elapsed = (int)Stopwatch.GetElapsedTime(timestamp).TotalSeconds;
128-
return new TextToImageResult(fileInfo.OutputImage, fileInfo.OutputImageUrl, options, fileInfo.OutputOptionsUrl, elapsed);
99+
return new TextToImageResult(fileInfo.Image, fileInfo.ImageUrl, blueprint, fileInfo.Blueprint, fileInfo.BlueprintUrl, elapsed);
129100
}
130101

131102

@@ -141,7 +112,7 @@ private async Task<bool> RunStableDiffusion(PromptOptions promptOptions, Schedul
141112
{
142113
try
143114
{
144-
await _stableDiffusionService.TextToImageFile(promptOptions, schedulerOptions, fileInfo.OutputImageFile, ProgressCallback(), cancellationToken);
115+
await _stableDiffusionService.TextToImageFile(promptOptions, schedulerOptions, fileInfo.ImageFile, ProgressCallback(), cancellationToken);
145116
return true;
146117
}
147118
catch (OperationCanceledException tex)
@@ -164,13 +135,13 @@ private async Task<bool> RunStableDiffusion(PromptOptions promptOptions, Schedul
164135
/// <param name="fileInfo">The file information.</param>
165136
/// <param name="options">The options.</param>
166137
/// <returns></returns>
167-
private async Task<bool> SaveOptionsFile(FileInfoResult fileInfo, TextToImageOptions options)
138+
private async Task<bool> SaveBlueprintFile(FileInfoResult fileInfo, ImageBlueprint bluprint)
168139
{
169140
try
170141
{
171-
using (var stream = File.Create(fileInfo.OutputOptionsFile))
142+
using (var stream = File.Create(fileInfo.BlueprintFile))
172143
{
173-
await JsonSerializer.SerializeAsync(stream, options, _serializerOptions);
144+
await JsonSerializer.SerializeAsync(stream, bluprint, _serializerOptions);
174145
return true;
175146
}
176147
}
@@ -257,6 +228,11 @@ private string CreateOutputUrl(string folder, string file)
257228
}
258229

259230
public record ProgressResult(int Progress, int Total);
260-
public record TextToImageResult(string OutputImage, string OutputImageUrl, TextToImageOptions OutputOptions, string OutputOptionsUrl, int Elapsed);
261-
public record FileInfoResult(string OutputImage, string OutputImageUrl, string OutputImageFile, string OutputOptions, string OutputOptionsUrl, string OutputOptionsFile);
231+
public record TextToImageResult(string ImageName, string ImageUrl, ImageBlueprint Blueprint, string BlueprintName, string BlueprintUrl, int Elapsed);
232+
public record FileInfoResult(string Image, string ImageUrl, string ImageFile, string Blueprint, string BlueprintUrl, string BlueprintFile);
233+
234+
public record ImageBlueprint(PromptOptions Prompt, SchedulerOptions Options)
235+
{
236+
public DateTime Timestamp { get; } = DateTime.UtcNow;
237+
}
262238
}

OnnxStack.WebUI/Pages/Shared/_Layout.cshtml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>@ViewData["Title"] - OnnxStack.WebUI</title>
7-
<link rel="stylesheet" href="~/lib/bootstrap/dist/bootstrap.css?=2" />
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/default.css" id="themeStylesheet" />
88
<link rel="stylesheet" href="~/css/fontawesome.css" />
99
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
1010
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/croppie/2.6.5/croppie.min.css" />
1111
<script src="~/lib/jquery/dist/jquery.min.js"></script>
1212
</head>
1313
<body>
1414
<header>
15-
<nav class="navbar navbar-expand-sm navbar-toggleable-sm bg-dark border-bottom box-shadow" data-bs-theme="dark">
15+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm border-bottom box-shadow bg-primary" data-bs-theme="dark">
1616
<div class="container-fluid">
1717
<a class="navbar-brand" asp-area="" asp-page="/Index">OnnxStack.WebUI</a>
1818
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
@@ -28,6 +28,22 @@
2828
<a class="nav-link" asp-area="" asp-page="/StableDiffusion/Index">Stable Diffusion</a>
2929
</li>
3030
</ul>
31+
<div>
32+
<select id="select-theme" class="form-control form-select form-select-sm bg-primary border-dark">
33+
<option value="default">Default</option>
34+
<option value="cyborg">Cyborg</option>
35+
<option value="darkly">Darkly</option>
36+
<option value="morph">Morph</option>
37+
<option value="quartz">Quartz</option>
38+
<option value="simplex">Simplex</option>
39+
<option value="sketchy">Sketchy</option>
40+
<option value="slate">Slate</option>
41+
<option value="solar">Solar</option>
42+
<option value="spacelab">Spacelab</option>
43+
<option value="vapor">Vapor</option>
44+
<option value="zephyr">Zephyr</option>
45+
</select>
46+
</div>
3147
</div>
3248
</div>
3349
</nav>
@@ -47,6 +63,24 @@
4763
await Html.RenderPartialAsync("_SharedTemplates");
4864
}
4965

66+
<script>
67+
const applyTheme = (theme) => {
68+
const link = document.getElementById("themeStylesheet");
69+
const newTheme = `/lib/bootstrap/dist/${theme}.css`;
70+
if (link.href.includes(newTheme))
71+
return;
72+
73+
link.href = newTheme;
74+
}
75+
76+
let storedTheme = localStorage.getItem("selectedTheme");
77+
if (!storedTheme) {
78+
storedTheme = "default"
79+
localStorage.setItem("selectedTheme", storedTheme);
80+
}
81+
applyTheme(storedTheme);
82+
</script>
83+
5084

5185
<script src="~/lib/jquery.unobtrusive-ajax.min.js"></script>
5286
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
@@ -55,6 +89,15 @@
5589
<script src="~/lib/modal.js"></script>
5690
<script src="https://cdnjs.cloudflare.com/ajax/libs/croppie/2.6.5/croppie.min.js"></script>
5791
<script src="~/js/site.js" asp-append-version="true"></script>
92+
<script>
93+
$("#select-theme").val(storedTheme);
94+
$("#select-theme").on("change", function () {
95+
const theme = $(this).find("option:selected").val();
96+
localStorage.setItem("selectedTheme", theme);
97+
applyTheme(theme);
98+
});
99+
</script>
100+
58101

59102
@await RenderSectionAsync("Scripts", required: false)
60103
</body>

0 commit comments

Comments
 (0)