Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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(())
}

About

unofficial api wrapper for fusionbrain.ai

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Used by

Contributors

Languages