diff --git a/Diffusion-macOS/ContentView.swift b/Diffusion-macOS/ContentView.swift index 3d25826..a3bc5bc 100644 --- a/Diffusion-macOS/ContentView.swift +++ b/Diffusion-macOS/ContentView.swift @@ -66,7 +66,8 @@ struct ContentView: View { @StateObject var generation = GenerationContext() func toolbar() -> any View { - if case .complete(let prompt, let cgImage, let seed, _) = generation.state, let cgImage = cgImage { + if case .complete(let prompt, let cgImage, _, _) = generation.state, let cgImage = cgImage { + // TODO: share seed too return ShareButtons(image: cgImage, name: prompt) } else { let prompt = DEFAULT_PROMPT diff --git a/Diffusion-macOS/ControlsView.swift b/Diffusion-macOS/ControlsView.swift index b697b7c..ea04b82 100644 --- a/Diffusion-macOS/ControlsView.swift +++ b/Diffusion-macOS/ControlsView.swift @@ -70,6 +70,9 @@ struct ControlsView: View { @State private var showGuidanceHelp = false @State private var showStepsHelp = false @State private var showSeedHelp = false + + // Reasonable range for the slider + let maxSeed: UInt32 = 1000 func updateSafetyCheckerState() { mustShowSafetyCheckerDisclaimer = generation.disableSafety && !Settings.shared.safetyCheckerDisclaimerShown @@ -82,7 +85,7 @@ struct ControlsView: View { pipelineLoader?.cancel() pipelineState = .downloading(0) Task.init { - let loader = PipelineLoader(model: model) + let loader = PipelineLoader(model: model, maxSeed: maxSeed) self.pipelineLoader = loader stateSubscriber = loader.statePublisher.sink { state in DispatchQueue.main.async { @@ -245,7 +248,7 @@ struct ControlsView: View { DisclosureGroup(isExpanded: $disclosedSeed) { let sliderLabel = generation.seed < 0 ? "Random Seed" : "Seed" - CompactSlider(value: $generation.seed, in: -1...1000, step: 1) { + CompactSlider(value: $generation.seed, in: -1...Double(maxSeed), step: 1) { Text(sliderLabel) Spacer() Text("\(Int(generation.seed))") diff --git a/Diffusion-macOS/StatusView.swift b/Diffusion-macOS/StatusView.swift index 456279f..01b91ac 100644 --- a/Diffusion-macOS/StatusView.swift +++ b/Diffusion-macOS/StatusView.swift @@ -83,6 +83,12 @@ struct StatusView: View { let intervalString = String(format: "Time: %.1fs", interval ?? 0) Text(intervalString) Spacer() + if generation.seed != Double(lastSeed) { + Text("Seed: \(lastSeed)") + Button("Set") { + generation.seed = Double(lastSeed) + } + } }.frame(maxHeight: 25) case .failed(let error): return errorWithDetails("Generation error", error: error) diff --git a/Diffusion/Pipeline/Pipeline.swift b/Diffusion/Pipeline/Pipeline.swift index 3f04aa6..63b5a78 100644 --- a/Diffusion/Pipeline/Pipeline.swift +++ b/Diffusion/Pipeline/Pipeline.swift @@ -22,6 +22,7 @@ struct GenerationResult { class Pipeline { let pipeline: StableDiffusionPipeline + let maxSeed: UInt32 var progress: StableDiffusionProgress? = nil { didSet { @@ -31,8 +32,9 @@ class Pipeline { lazy private(set) var progressPublisher: CurrentValueSubject = CurrentValueSubject(progress) - init(_ pipeline: StableDiffusionPipeline) { + init(_ pipeline: StableDiffusionPipeline, maxSeed: UInt32 = UInt32.max) { self.pipeline = pipeline + self.maxSeed = maxSeed } func generate( @@ -46,7 +48,7 @@ class Pipeline { ) throws -> GenerationResult { let beginDate = Date() print("Generating...") - let theSeed = seed ?? UInt32.random(in: 0..