mirror of
https://github.com/GayPizzaSpecifications/stable-diffusion-rpc.git
synced 2025-08-04 14:01:32 +00:00
Support for starting images and many more parameters.
This commit is contained in:
@ -3,5 +3,6 @@ import Foundation
|
||||
public enum SdCoreError: Error {
|
||||
case modelNotLoaded
|
||||
case imageEncodeFailed
|
||||
case imageDecodeFailed
|
||||
case modelNotFound
|
||||
}
|
||||
|
@ -36,3 +36,20 @@ extension CGImage {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension SdImage {
|
||||
func toCgImage() throws -> CGImage {
|
||||
guard let dataProvider = CGDataProvider(data: data as CFData) else {
|
||||
throw SdCoreError.imageDecodeFailed
|
||||
}
|
||||
|
||||
if format == .png {
|
||||
guard let image = CGImage(pngDataProviderSource: dataProvider, decode: nil, shouldInterpolate: false, intent: .defaultIntent) else {
|
||||
throw SdCoreError.imageDecodeFailed
|
||||
}
|
||||
return image
|
||||
} else {
|
||||
throw SdCoreError.imageDecodeFailed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,31 @@ public actor ModelState {
|
||||
var pipelineConfig = StableDiffusionPipeline.Configuration(prompt: request.prompt)
|
||||
pipelineConfig.negativePrompt = request.negativePrompt
|
||||
pipelineConfig.imageCount = Int(request.batchSize)
|
||||
|
||||
if request.hasStartingImage {
|
||||
pipelineConfig.startingImage = try request.startingImage.toCgImage()
|
||||
}
|
||||
|
||||
if request.guidanceScale != 0.0 {
|
||||
pipelineConfig.guidanceScale = request.guidanceScale
|
||||
}
|
||||
|
||||
if request.stepCount != 0 {
|
||||
pipelineConfig.stepCount = Int(request.stepCount)
|
||||
}
|
||||
|
||||
if request.strength != 0.0 {
|
||||
pipelineConfig.strength = request.strength
|
||||
}
|
||||
|
||||
pipelineConfig.disableSafety = !request.enableSafetyCheck
|
||||
|
||||
switch request.scheduler {
|
||||
case .pndm: pipelineConfig.schedulerType = .pndmScheduler
|
||||
case .dpmSolverPlusPlus: pipelineConfig.schedulerType = .dpmSolverMultistepScheduler
|
||||
default: pipelineConfig.schedulerType = .pndmScheduler
|
||||
}
|
||||
|
||||
var response = SdGenerateImagesResponse()
|
||||
for _ in 0 ..< request.batchCount {
|
||||
var seed = baseSeed
|
||||
|
Reference in New Issue
Block a user