1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use fal_rust::{
    client::{ClientCredentials, FalClient},
    utils::download_image,
};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
struct ImageResult {
    url: String,
}

#[derive(Debug, Serialize, Deserialize)]
struct Output {
    images: Vec<ImageResult>,
}

#[tokio::main]
async fn main() {
    let client = FalClient::new(ClientCredentials::from_env());

    let res = client
        .run(
            "fal-ai/stable-cascade",
            serde_json::json!({
                "prompt": "A large waterfall in the middle of a volcano, surrounded by lush greenery and children's playground equipment.",
            }),
        )
        .await
        .unwrap();

    let output: Output = res.json::<Output>().await.unwrap();

    let url = output.images[0].url.clone();
    let filename = url.split('/').last().unwrap();

    download_image(&url, format!("{}/{}", "images", filename).as_str())
        .await
        .unwrap();
}