mirror of
https://github.com/GayPizzaSpecifications/stable-diffusion-rpc.git
synced 2025-08-03 05:30:54 +00:00
40 lines
1.1 KiB
Swift
40 lines
1.1 KiB
Swift
import ArgumentParser
|
|
import Foundation
|
|
import GRPC
|
|
import NIO
|
|
import StableDiffusionCore
|
|
import System
|
|
|
|
struct ServerCommand: ParsableCommand {
|
|
@Option(name: .shortAndLong, help: "Path to models directory")
|
|
var modelsDirectoryPath: String = "models"
|
|
|
|
mutating func run() throws {
|
|
let modelsDirectoryURL = URL(filePath: modelsDirectoryPath)
|
|
let modelManager = ModelManager(modelBaseURL: modelsDirectoryURL)
|
|
|
|
let semaphore = DispatchSemaphore(value: 0)
|
|
Task {
|
|
do {
|
|
try await modelManager.reloadModels()
|
|
} 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)
|
|
|
|
dispatchMain()
|
|
}
|
|
}
|
|
|
|
ServerCommand.main()
|