https://github.com/rwxbytes/stability_rs
A Rust lib crate for Stability.ai
https://github.com/rwxbytes/stability_rs
ai api stable-diffusion text-to-image
Last synced: 10 months ago
JSON representation
A Rust lib crate for Stability.ai
- Host: GitHub
- URL: https://github.com/rwxbytes/stability_rs
- Owner: rwxbytes
- Created: 2023-08-29T18:25:33.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-27T17:31:28.000Z (over 2 years ago)
- Last Synced: 2025-03-16T17:36:59.595Z (about 1 year ago)
- Topics: ai, api, stable-diffusion, text-to-image
- Language: Rust
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
An unofficial Rust API client for [Stability-AI](https://stability.ai/) text-to-speech software.
## ⚙️ Requirements
- Set API key to environment variable `STABILITY_API_KEY`
## 🗣️ Usage
### Text to Image
```rust
use stability_rs::{text_to_img::*, Result, ClipGuidancePreset, Sampler, StylePreset};
#[tokio::main]
async fn main() -> Result<()> {
let image = TextToImageBuilder::new()
.height(1024)?
.width(1024)?
.cfg_scale(27)?
.clip_guidance_preset(ClipGuidancePreset::FastBlue)?
.sampler(Sampler::KDpmpp2sAncestral)?
.samples(2)?
.seed(0)?
.steps(33)?
.style_preset(StylePreset::DigitalArt)?
.text_prompt("A scholar tired at his desk, a raven on a bust", 1.0)?
.build()?;
let resp = image.generate("stable-diffusion-xl-1024-v1-0").await?;
for (i, image) in resp.artifacts.iter().enumerate() {
let _ = image.save(&format!("image_{}.png", i)).await?;
}
Ok(())
}
```
### Image to Image
```rust
use stability_rs::{img_to_img::*, Result, ClipGuidancePreset, Sampler, StylePreset,};
#[tokio::main]
async fn main() -> Result<()> {
let image = ImageToImageBuilder::new()
.init_image_path("init_image.png")?
.init_image_mode(ImageMode::ImageStrength)?
.image_strength(0.35)?
.cfg_scale(7)?
.clip_guidance_preset(ClipGuidancePreset::FastBlue)?
.sampler(Sampler::KDpm2Ancestral)?
.samples(3)?
.seed(0)?
.steps(20)?
.style_preset(StylePreset::FantasyArt)?
.text_prompt("A crab relaxing on a beach", 0.5)?
.text_prompt("stones", -0.9)?
.build()?;
let resp = image.generate("stable-diffusion-xl-1024-v1-0").await?;
for (i, img) in resp.artifacts.iter().enumerate() {
let _ = img.save(&format!("new_image_{}.png", i)).await?;
}
Ok(())
}
```
### Image Upscaling
```rust
use stability_rs::{upscale::*, Result,};
#[tokio::main]
async fn main() -> Result<()> {
let image = UpscalerBuilder::new()
.image("1024_image.png")?
.height(2048)?
.build()?;
let resp = image.generate(UpscaleEngine::EsrganV1X2Plus).await?;
resp.artifacts.first().unwrap().save("2048_image.png").await?;
Ok(())
}
```
### Image Masking
```rust
use stability_rs::{masking::*, Result, StylePreset, ClipGuidancePreset};
#[tokio::main]
async fn main() -> Result<()> {
let engine = "stable-inpainting-512-v2-0";
let image = MaskerBuilder::new()
.init_image_path("init_image.png")?
.mask_source(MaskSource::MaskImageBlack)?
.mask_image("black_mask_image.png")?
.text_prompt("a crab dancing", 1.0)?
.style_preset(StylePreset::FantasyArt)?
.clip_guidance_preset(ClipGuidancePreset::FastBlue)?
.build()?;
let resp = image.generate(engine).await?;
resp.artifacts.first().unwrap().save("masked_image.png").await?;
Ok(())
}
```