Crates.io | stabilityai |
lib.rs | stabilityai |
version | 0.1.0 |
source | src |
created_at | 2023-08-25 09:35:15.514222 |
updated_at | 2023-08-25 09:35:15.514222 |
description | stability.ai library based on OpenAPI spec |
homepage | https://github.com/64bit/stabilityai |
repository | https://github.com/64bit/stabilityai |
max_upload_size | |
id | 954536 |
size | 59,983 |
Rust library for stability.ai
stabilityai
is an unofficial Rust library for stability.ai
The library reads API key from the environment variable STABILITY_API_KEY
.
# On macOS/Linux
export STABILITY_API_KEY='sk-...'
# On Windows Powershell
$Env:STABILITY_API_KEY='sk-...'
use stabilityai::{
error::StabilityAIError,
types::{ClipGuidancePreset, Sampler, StylePreset, TextToImageRequestBodyArgs},
Client,
};
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// create client, reads STABILITY_API_KEY environment variable for API key.
let client = Client::new();
let request = TextToImageRequestBodyArgs::default()
.text_prompts(
"A banner with ocean background having a cute \
red cartoon crab on beach and boats in the ocean",
)
.samples(1)
.steps(30_u32)
.clip_guidance_preset(ClipGuidancePreset::FastBlue)
.sampler(Sampler::KDpmpp2sAncestral)
.width(1216_u16)
.height(832_u16)
.style_preset(StylePreset::ThreeDModel)
.build()?;
let artifacts = client
.generate("stable-diffusion-xl-1024-v1-0")
.text_to_image(request)
.await?;
// Create directory if doesn't exist and save images
let paths = artifacts.save("./data").await?;
paths
.iter()
.for_each(|path| println!("Image saved at {}", path.display()));
Ok(())
}
Thank you for your time to contribute and improve the project, I'd be happy to have you!
A good starting point cloud be an existing open issue.
This project is licensed under MIT license.