@@ -25,7 +25,7 @@ public sealed class StableDiffusionService : IStableDiffusionService
2525 {
2626 private readonly IOnnxModelService _onnxModelService ;
2727 private readonly StableDiffusionConfig _configuration ;
28- private readonly IDictionary < DiffuserType , IDiffuser > _diffusers ;
28+ private readonly IDictionary < DiffuserPipelineType , IDictionary < DiffuserType , IDiffuser > > _diffusers ;
2929
3030 /// <summary>
3131 /// Initializes a new instance of the <see cref="StableDiffusionService"/> class.
@@ -35,11 +35,21 @@ public StableDiffusionService(StableDiffusionConfig configuration, IOnnxModelSer
3535 {
3636 _configuration = configuration ;
3737 _onnxModelService = onnxModelService ;
38- _diffusers = new ConcurrentDictionary < DiffuserType , IDiffuser > ( ) ;
39- _diffusers . Add ( DiffuserType . TextToImage , new TextDiffuser ( onnxModelService , promptService ) ) ;
40- _diffusers . Add ( DiffuserType . ImageToImage , new ImageDiffuser ( onnxModelService , promptService ) ) ;
41- _diffusers . Add ( DiffuserType . ImageInpaint , new InpaintDiffuser ( onnxModelService , promptService ) ) ;
42- _diffusers . Add ( DiffuserType . ImageInpaintLegacy , new InpaintLegacyDiffuser ( onnxModelService , promptService ) ) ;
38+ var stableDiffusionPipeline = new Dictionary < DiffuserType , IDiffuser >
39+ {
40+ { DiffuserType . TextToImage , new TextDiffuser ( onnxModelService , promptService ) } ,
41+ { DiffuserType . ImageToImage , new ImageDiffuser ( onnxModelService , promptService ) } ,
42+ { DiffuserType . ImageInpaint , new InpaintDiffuser ( onnxModelService , promptService ) } ,
43+ { DiffuserType . ImageInpaintLegacy , new InpaintLegacyDiffuser ( onnxModelService , promptService ) }
44+ } ;
45+
46+ var latentConsistancyPipeline = new Dictionary < DiffuserType , IDiffuser >
47+ {
48+ //TODO: TextToImage and ImageToImage is supported with LCM
49+ } ;
50+
51+ _diffusers . Add ( DiffuserPipelineType . StableDiffusion , stableDiffusionPipeline ) ;
52+ _diffusers . Add ( DiffuserPipelineType . LatentConsistency , latentConsistancyPipeline ) ;
4353 }
4454
4555
@@ -146,8 +156,15 @@ public async Task<Stream> GenerateAsStreamAsync(IModelOptions model, PromptOptio
146156
147157 private async Task < DenseTensor < float > > DiffuseAsync ( IModelOptions modelOptions , PromptOptions promptOptions , SchedulerOptions schedulerOptions , Action < int , int > progress = null , CancellationToken cancellationToken = default )
148158 {
149- return await _diffusers [ promptOptions . DiffuserType ]
150- . DiffuseAsync ( modelOptions , promptOptions , schedulerOptions , progress , cancellationToken ) ;
159+ var pipeline = _diffusers [ modelOptions . PipelineType ] ;
160+ if ( pipeline is null )
161+ throw new Exception ( "Pipeline not found or is unsupported" ) ;
162+
163+ var diffuser = pipeline [ promptOptions . DiffuserType ] ;
164+ if ( diffuser is null )
165+ throw new Exception ( "Diffuser not found or is unsupported" ) ;
166+
167+ return await diffuser . DiffuseAsync ( modelOptions , promptOptions , schedulerOptions , progress , cancellationToken ) ;
151168 }
152169 }
153170}
0 commit comments