Files
stable-diffusion-rpc/Sources/StableDiffusionServer/main.swift

40 lines
1.1 KiB
Swift
Raw Normal View History

2023-04-22 14:52:27 -07:00
import ArgumentParser
import Foundation
2023-04-22 14:52:27 -07:00
import GRPC
import NIO
import StableDiffusionCore
2023-04-22 14:52:27 -07:00
import System
struct ServerCommand: ParsableCommand {
@Option(name: .shortAndLong, help: "Path to models directory")
var modelsDirectoryPath: String = "models"
2023-04-22 14:52:27 -07:00
mutating func run() throws {
let modelsDirectoryURL = URL(filePath: modelsDirectoryPath)
let modelManager = ModelManager(modelBaseURL: modelsDirectoryURL)
2023-04-22 14:52:27 -07:00
let semaphore = DispatchSemaphore(value: 0)
Task {
do {
try await modelManager.reloadAvailableModels()
2023-04-22 14:52:27 -07:00
} catch {
ServerCommand.exit(withError: error)
}
semaphore.signal()
}
semaphore.wait()
let group = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
_ = Server.insecure(group: group)
.withServiceProviders([
ModelServiceProvider(modelManager: modelManager),
ImageGenerationServiceProvider(modelManager: modelManager)
])
.bind(host: "0.0.0.0", port: 4546)
2023-04-22 14:52:27 -07:00
dispatchMain()
}
}
2023-04-22 14:52:27 -07:00
ServerCommand.main()