Crates.io | flopper |
lib.rs | flopper |
version | 0.0.11 |
source | src |
created_at | 2024-09-25 12:55:21.566503 |
updated_at | 2024-09-25 13:00:13.441662 |
description | unofficial api wrapper for fusionbrain.ai |
homepage | |
repository | https://github.com/TOwInOK/flopper |
max_upload_size | |
id | 1386303 |
size | 59,827 |
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.
Best folder ever => examples
Note: create .env
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(())
}
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(())
}