flopper

Crates.ioflopper
lib.rsflopper
version0.0.11
sourcesrc
created_at2024-09-25 12:55:21.566503
updated_at2024-09-25 13:00:13.441662
descriptionunofficial api wrapper for fusionbrain.ai
homepage
repositoryhttps://github.com/TOwInOK/flopper
max_upload_size
id1386303
size59,827
TOwInOK#nqcq (TOwInOK)

documentation

README

Flopper

Crates.io Documentation License

Flopper is an async Rust library for generating images using fusionbrain api.

Note: still in development. Please, use it with caution.

If you have any questions or suggestions, open an issue.

Examples

Best folder ever => examples

Note: create .env

Usual example

use flopper::prelude::*; 
use dotenvy_macro::dotenv;

#[tokio::main]
async main () -> anyhow::Result<()>{
    // parse .env vars
    let key: &str = dotenv!("KEY");
    let secret: &str = dotenv!("SECRET");
    // Init Flopper instance
    let flopper = Flopper::build(key.to_string(), secret.to_string(), None, None).await?;

    // Make params by default and add your params
    let mut params = Params::default();
    params.q("cat".to_string());
    // or create params with new()
    let params = Params::new(GenType::Generate, 1, 512, 512, "cat".to_string());

    // Push request to generate image
    let info = flopper.push(params).await?;
    // Start fetching
    let images = flopper.try_fetch(info).await?;
    let image = images[0].clone(); // we need to clone

    // Convert image from base64 to image
    let image = base64::engine::general_purpose::STANDARD.decode(image)?;
    // Save image to file
    std::fs::write("test_image.png", image)?;

    Ok(())
}

Macro example

use flopper::prelude::*; 
use dotenvy_macro::dotenv;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // parse .env
    let key: &str = dotenv!("KEY");
    let secret: &str = dotenv!("SECRET");

    // Use flop macro to fetch images.
    let images = flop!(
        key,
        secret,
        n = 1,                    // optional!
        w = 512,                  // optional but required
        h = 512,                  // optional but required
        q = "forest".to_string(), // optional but required
        m = 4                     // optional!
    );
    // convert from base64 to png
    let image = base64::engine::general_purpose::STANDARD.decode(images[0].clone())?;
    // write to test_image.png
    std::fs::write("test_image.png", image)?;

    Ok(())
}
Commit count: 7

cargo fmt