Module replicate_rust::prediction
source · Expand description
Used to interact with the Prediction Endpoints.
Example
let replicate = Replicate::new();
// Construct 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");
// Print the result.
match result {
Ok(result) => println!("Success : {:?}", result.output),
Err(e) => println!("Error : {}", e),
}
Another example to showcase other methods
let replicate = Replicate::new();
// Construct 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 mut prediction = replicate.predictions.create(version, inputs);
println!("Prediction : {:?}", prediction.status);
// Refetch the prediction using the reload method.
let _ = prediction.reload();
println!("Prediction : {:?}", prediction.status);
// Cancel the prediction.
let _ = prediction.cancel();
println!("Predictions : {:?}", prediction.status);;
// Wait for the prediction to complete (or fail).
match prediction.wait() {
Ok(result) => println!("Success : {:?}", result.output),
Err(e) => println!("Error : {}", e),
}