|
|
@ -15,7 +15,7 @@ let scheduler = StableDiffusionScheduler.dpmSolverMultistepScheduler
|
|
|
|
let steps = 25
|
|
|
|
let steps = 25
|
|
|
|
let seed: UInt32? = nil
|
|
|
|
let seed: UInt32? = nil
|
|
|
|
|
|
|
|
|
|
|
|
func generate(pipeline: Pipeline?, prompt: String) async -> CGImage? {
|
|
|
|
func generate(pipeline: Pipeline?, prompt: String) async -> (CGImage, TimeInterval)? {
|
|
|
|
guard let pipeline = pipeline else { return nil }
|
|
|
|
guard let pipeline = pipeline else { return nil }
|
|
|
|
return try? pipeline.generate(prompt: prompt, scheduler: scheduler, numInferenceSteps: steps, seed: seed)
|
|
|
|
return try? pipeline.generate(prompt: prompt, scheduler: scheduler, numInferenceSteps: steps, seed: seed)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -23,7 +23,7 @@ func generate(pipeline: Pipeline?, prompt: String) async -> CGImage? {
|
|
|
|
enum GenerationState {
|
|
|
|
enum GenerationState {
|
|
|
|
case startup
|
|
|
|
case startup
|
|
|
|
case running(StableDiffusionProgress?)
|
|
|
|
case running(StableDiffusionProgress?)
|
|
|
|
case idle(String)
|
|
|
|
case idle(String, TimeInterval?)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Presents "Share" + "Save" buttons on Mac; just "Share" on iOS/iPadOS.
|
|
|
|
/// Presents "Share" + "Save" buttons on Mac; just "Share" on iOS/iPadOS.
|
|
|
@ -82,7 +82,7 @@ struct ImageWithPlaceholder: View {
|
|
|
|
let fraction = Double(step) / Double(progress.stepCount)
|
|
|
|
let fraction = Double(step) / Double(progress.stepCount)
|
|
|
|
let label = "Step \(step) of \(progress.stepCount)"
|
|
|
|
let label = "Step \(step) of \(progress.stepCount)"
|
|
|
|
return AnyView(ProgressView(label, value: fraction, total: 1).padding())
|
|
|
|
return AnyView(ProgressView(label, value: fraction, total: 1).padding())
|
|
|
|
case .idle(let lastPrompt):
|
|
|
|
case .idle(let lastPrompt, let interval):
|
|
|
|
guard let theImage = image.wrappedValue else {
|
|
|
|
guard let theImage = image.wrappedValue else {
|
|
|
|
return AnyView(Image(systemName: "exclamationmark.triangle").resizable())
|
|
|
|
return AnyView(Image(systemName: "exclamationmark.triangle").resizable())
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -91,7 +91,14 @@ struct ImageWithPlaceholder: View {
|
|
|
|
return AnyView(
|
|
|
|
return AnyView(
|
|
|
|
VStack {
|
|
|
|
VStack {
|
|
|
|
imageView.resizable().clipShape(RoundedRectangle(cornerRadius: 20))
|
|
|
|
imageView.resizable().clipShape(RoundedRectangle(cornerRadius: 20))
|
|
|
|
|
|
|
|
HStack {
|
|
|
|
|
|
|
|
if let interval = interval {
|
|
|
|
|
|
|
|
Text(String(format:"Time: %.1fs", interval))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
ShareButtons(image: theImage, name: lastPrompt)
|
|
|
|
ShareButtons(image: theImage, name: lastPrompt)
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -110,8 +117,9 @@ struct TextToImage: View {
|
|
|
|
if case .running = state { return }
|
|
|
|
if case .running = state { return }
|
|
|
|
Task {
|
|
|
|
Task {
|
|
|
|
state = .running(nil)
|
|
|
|
state = .running(nil)
|
|
|
|
image = await generate(pipeline: context.pipeline, prompt: prompt)
|
|
|
|
let interval: TimeInterval?
|
|
|
|
state = .idle(prompt)
|
|
|
|
(image, interval) = await generate(pipeline: context.pipeline, prompt: prompt) ?? (nil, nil)
|
|
|
|
|
|
|
|
state = .idle(prompt, interval)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|