Crate replicate_rust

source ·
Expand description

Rust Client for interacting with the Replicate API.

Example

In this example we will run a model that generates a caption for an image using the Stable Diffusion model.

use replicate::Replicate;

// Reading the API key from an environment variable.
let api_key = std::env::var("REPLICATE_API_TOKEN").unwrap_or_else(|_| {
    eprintln!("REPLICATE_API_TOKEN not set");
    std::process::exit(1)
});

// Create a new Replicate client.
let replicate = Replicate::new(api_key)

// Creating the inputs
let mut inputs = std::collections::HashMap::new();
inputs.insert("prompt", "a  19th century portrait of a wombat gentleman");

let version = String::from("stability-ai/stable-diffusion:27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478");

// Run the model.
let result = replicate.run(version, inputs);

// Print the result
match result {
    Ok(result) => println!("Success : {:?}", result.output),
    Err(e) => println!("Error : {}", e),
}

Modules

Structs