Implement the ability to optionally collect intermediate images.

This commit is contained in:
2023-04-23 14:50:45 -07:00
parent d24d299a7d
commit 5704654d1a
6 changed files with 91 additions and 15 deletions

View File

@ -84,18 +84,22 @@ public actor ModelState {
pipelineConfig.seed = seed
let cgImages = try pipeline.generateImages(configuration: pipelineConfig, progressHandler: { progress in
let percentage = (Float(progress.step) / Float(progress.stepCount)) * 100.0
var images: [SdImage]?
if request.sendIntermediates {
images = try? cgImagesToImages(request: request, progress.currentImages)
}
let finalImages = images
Task {
do {
try await stream.send(.with { item in
item.currentBatch = batch
item.batchProgress = .with { update in
update.percentageComplete = percentage
try await stream.send(.with { item in
item.currentBatch = batch
item.batchProgress = .with { update in
update.percentageComplete = percentage
if let finalImages {
update.images = finalImages
}
item.overallPercentageComplete = currentOverallPercentage(percentage)
})
} catch {
fatalError(error.localizedDescription)
}
}
item.overallPercentageComplete = currentOverallPercentage(percentage)
})
}
return true
})