mirror of
https://github.com/GayPizzaSpecifications/stable-diffusion-rpc.git
synced 2025-08-04 05:51:32 +00:00
Initial Commit
This commit is contained in:
40
Sources/StableDiffusionServer/main.swift
Normal file
40
Sources/StableDiffusionServer/main.swift
Normal file
@ -0,0 +1,40 @@
|
||||
import Foundation
|
||||
import ArgumentParser
|
||||
import GRPC
|
||||
import NIO
|
||||
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 {
|
||||
print("Loading initial models...")
|
||||
do {
|
||||
try await modelManager.reloadModels()
|
||||
} catch {
|
||||
ServerCommand.exit(withError: error)
|
||||
}
|
||||
print("Loaded initial models.")
|
||||
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()
|
Reference in New Issue
Block a user