Skip to content

Commit

Permalink
fix: swift-format issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-detr committed Mar 14, 2024
1 parent 1e7808a commit 77bc00f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
20 changes: 10 additions & 10 deletions Mochi Diffusion/Support/ImageGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ struct GenerationConfig: Sendable, Identifiable {
}

@Observable public final class ImageGenerator {

static let shared = ImageGenerator()

enum GeneratorError: Error {
Expand Down Expand Up @@ -88,8 +87,7 @@ struct GenerationConfig: Sendable, Identifiable {
let items = try fm.contentsOfDirectory(
at: finalImageDirURL,
includingPropertiesForKeys: nil,
options: .skipsHiddenFiles
)
options: .skipsHiddenFiles)
let imageURLs =
items
.filter { $0.isFileURL }
Expand Down Expand Up @@ -192,24 +190,26 @@ struct GenerationConfig: Sendable, Identifiable {
self.pipeline = try StableDiffusionXLPipeline(
resourcesAt: model.url,
configuration: config,
reduceMemory: reduceMemory
)
reduceMemory: reduceMemory)
} else {
self.pipeline = try StableDiffusionPipeline(
resourcesAt: model.url,
controlNet: controlNet,
configuration: config,
disableSafety: true,
reduceMemory: reduceMemory
)
reduceMemory: reduceMemory)
}

self.currentPipelineHash = hash
self.tokenizer = Tokenizer(modelDir: model.url)
}

func loadPipeline(model: SDModel, controlNet: [String] = [], computeUnit: MLComputeUnits, reduceMemory: Bool) async throws {
try await preparePipeline(model: model, controlNet: controlNet, computeUnit: computeUnit, reduceMemory: reduceMemory)
func loadPipeline(
model: SDModel, controlNet: [String] = [], computeUnit: MLComputeUnits, reduceMemory: Bool
) async throws {
try await preparePipeline(
model: model, controlNet: controlNet, computeUnit: computeUnit,
reduceMemory: reduceMemory)
await updateState(.ready(nil))
}

Expand Down Expand Up @@ -289,7 +289,7 @@ struct GenerationConfig: Sendable, Identifiable {
sdi.generatedDate = Date.now
sdi.path = ""

if config.autosaveImages && !config.imageDir.isEmpty {
if config.autosaveImages, !config.imageDir.isEmpty {
var pathURL = URL(fileURLWithPath: config.imageDir, isDirectory: true)
let count = ImageStore.shared.images.endIndex + 1
pathURL.append(path: sdi.filenameWithoutExtension(count: count))
Expand Down
16 changes: 8 additions & 8 deletions Mochi Diffusion/Views/GalleryPreviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ struct GalleryPreviewView: View {
.resizable()
.aspectRatio(contentMode: .fit)
}
.overlay(
RoundedRectangle(cornerRadius: 2)
.stroke(strokeColor, lineWidth: 4)
)
.onReceive(timer) { _ in
withAnimation(.linear(duration: 1)) {
strokeColor = (strokeColor == .black) ? .cyan : .black
}
.overlay(
RoundedRectangle(cornerRadius: 2)
.stroke(strokeColor, lineWidth: 4)
)
.onReceive(timer) { _ in
withAnimation(.linear(duration: 1)) {
strokeColor = (strokeColor == .black) ? .cyan : .black
}
}
}
}
}
13 changes: 8 additions & 5 deletions Mochi Diffusion/Views/GalleryToolbarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ struct GalleryToolbarView: View {
}

ZStack {
if case .running(let progress) = generator.state, let progress = progress,
progress.stepCount > 0
{
if case let .running(progress) = generator.state, let progress = progress,
progress.stepCount > 0
{
Button {
self.isStatusPopoverShown.toggle()
} label: {
Expand Down Expand Up @@ -190,11 +190,14 @@ struct GalleryToolbarView: View {
@ViewBuilder
private func progressBarView() -> some View {
VStack(spacing: 0) {
if case let .running(progress) = generator.state, let progress = progress, progress.stepCount > 0 {
if case let .running(progress) = generator.state, let progress = progress,
progress.stepCount > 0
{
let step = progress.step + 1
let stepValue = Double(step) / Double(progress.stepCount)
let progressText = String(
localized: "About \(formatTimeRemaining(generator.lastStepGenerationElapsedTime, stepsLeft: progress.stepCount - step))",
localized:
"About \(formatTimeRemaining(generator.lastStepGenerationElapsedTime, stepsLeft: progress.stepCount - step))",
comment: "Text displaying the current time remaining"
)

Expand Down

0 comments on commit 77bc00f

Please sign in to comment.