@@ -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}
0 commit comments