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

Commit 4ae24c8

Browse files
committed
Add some input validation, fix missing await
1 parent 0f4ee6c commit 4ae24c8

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

OnnxStack.StableDiffusion/Config/PromptOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
using OnnxStack.StableDiffusion.Enums;
2+
using System.ComponentModel.DataAnnotations;
23

34
namespace OnnxStack.StableDiffusion.Config
45
{
56
public class PromptOptions
67
{
8+
[Required]
9+
[StringLength(512, MinimumLength = 4)]
710
public string Prompt { get; set; }
11+
12+
[StringLength(512)]
813
public string NegativePrompt { get; set; }
914
public SchedulerType SchedulerType { get; set; }
1015
public string InputImage { get; set; }

OnnxStack.StableDiffusion/Config/SchedulerOptions.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using OnnxStack.StableDiffusion.Enums;
22
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
34

45
namespace OnnxStack.StableDiffusion.Config
56
{
@@ -11,6 +12,7 @@ public class SchedulerOptions
1112
/// <value>
1213
/// The height of the image. Default is 512 and must be divisible by 64.
1314
/// </value>
15+
[Range(0, 4096)]
1416
public int Height { get; set; } = 512;
1517

1618
/// <summary>
@@ -19,6 +21,7 @@ public class SchedulerOptions
1921
/// <value>
2022
/// The width of the image. Default is 512 and must be divisible by 64.
2123
/// </value>
24+
[Range(0, 4096)]
2225
public int Width { get; set; } = 512;
2326

2427
/// <summary>
@@ -27,6 +30,7 @@ public class SchedulerOptions
2730
/// <value>
2831
/// If value is set to 0 a random seed is used.
2932
/// </value>
33+
[Range(0, int.MaxValue)]
3034
public int Seed { get; set; }
3135

3236
/// <summary>
@@ -35,6 +39,7 @@ public class SchedulerOptions
3539
/// <value>
3640
/// The number of steps to run inference for. The more steps the longer it will take to run the inference loop but the image quality should improve.
3741
/// </value>
42+
[Range(5, 200)]
3843
public int InferenceSteps { get; set; } = 15;
3944

4045
/// <summary>
@@ -43,18 +48,21 @@ public class SchedulerOptions
4348
/// <value>
4449
/// The scale for the classifier-free guidance. The higher the number the more it will try to look like the prompt but the image quality may suffer.
4550
/// </value>
51+
[Range(0f, 40f)]
4652
public float GuidanceScale { get; set; } = 7.5f;
4753

4854
/// <summary>
4955
/// Gets or sets the strength use for Image 2 Image
50-
/// </summary>
56+
[Range(0f, 1f)]
5157
public float Strength { get; set; } = 0.6f;
5258

5359
/// <summary>
5460
/// Gets or sets the initial noise level for Image 2 Image
5561
/// </summary>
62+
[Range(-1f, 1f)]
5663
public float InitialNoiseLevel { get; set; } = 0f;
5764

65+
[Range(0, int.MaxValue)]
5866
public int TrainTimesteps { get; set; } = 1000;
5967
public float BetaStart { get; set; } = 0.00085f;
6068
public float BetaEnd { get; set; } = 0.012f;

OnnxStack.WebUI/Services/FileService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public async Task<FileServiceResult> UploadImageFile(UploadImageModel model)
9494
{
9595
try
9696
{
97-
var rand = CreateRandomName();
97+
var rand = await CreateRandomName();
9898
var outputImage = $"Upload-{rand}.png";
9999
var outputImageUrl = await CreateOutputUrl(outputImage);
100100
var outputImageFile = await UrlToPhysicalPath(outputImageUrl);

0 commit comments

Comments
 (0)