Stability.ai KIT implementation for Swift enables seamless integration of Stability.ai API into your Swift-based applications.
- Get account information
- Get balance information
- Get engines
- Generate a new image from a text prompt
- Modify an image based on a text prompt
- Create a higher resolution version of an input image
- Selectively modify portions of an image using a mask
You can install the Stability.ai KIT package using Swift Package Manager. Add the following dependency to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/ftp27/stabilityai-kit", from: "1.0.0")
]
The framework is fully documented using Xcode's documentation system. You can also find the documentation online at appledoc.
To use the framework, first create a Configuration
instance with the necessary API key and optional client information:
let configuration = Configuration(apiKey: "YOUR_API_KEY")
You can also customize the clientId
, clientVersion
, organization
properties of the configuration if needed.
If you need to use a proxy to connect to the Stability AI API, you can set the api
property of the configuration:
let configuration = Configuration(
apiKey: "YOUR_API_KEY",
api: .init(
scheme: .https,
host: "proxyhost.com"
)
)
Once you have a configuration, create a Client
instance:
let client = Client(configuration: configuration)
The framework provides methods to interact with the Stability AI API. Here are some example requests:
do {
let account = try await client.getAccount()
// Use the account information
} catch {
// Handle error
}
do {
let balance = try await client.getBalance()
// Use the balance information
} catch {
// Handle error
}
do {
let engines = try await client.getEngines()
// Use the list of engines
} catch {
// Handle error
}
let request = TextToImageRequest(textPrompts: [.init(text: "your prompt")])
do {
let results = try await client.getImageFromText(request, engine: "ENGINE_ID")
// Use the resulting images
} catch {
// Handle error
}
let request = ImageToImageRequest
.strength(
textPrompts: [.init(text: "your prompt")]),
initImage: image.pngData()!,
strength: 0.5
)
.setStylePreset(.cinematic) // Optional
.setSteps(40) // Optional
do {
let results = try await client.getImageFromImage(request, engine: "ENGINE_ID")
// Use the resulting images
} catch {
// Handle error
}
Contributions are welcomed to the framework. If you have a feature request, bug report, or patch, please feel free to open an issue or pull request.
This Swift package is licensed under the MIT License. See the LICENSE file for more information.