Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

raea gen: image.edit's mask reaches a fal model's mask field

shinyobjectzc3ba126ccfff
diff --git a/io/gen-core/src/fal.rs b/io/gen-core/src/fal.rs
index 2fc292ee..010c0517 100644
--- a/io/gen-core/src/fal.rs
+++ b/io/gen-core/src/fal.rs
@@ -137,7 +137,13 @@ pub fn body(inputs: &serde_json::Map<String, J>, media: &[(String, String)], fie
_ => {}
}
}
- let images: Vec<&String> = media.iter().map(|(_, u)| u).collect();
+ // a mask (image.edit's `mask`: where an inpainting model may paint) into the endpoint's mask field, not with the
+ // pictures (it went into image_urls beside the picture, and a fill model read no mask)
+ if let Some((_, u)) = media.iter().find(|(n, _)| n == "mask") {
+ let f = fields.iter().find(|(n, l)| !*l && n.contains("mask")).map(|(n, _)| n.clone()).unwrap_or_else(|| "mask_url".into());
+ b[f.as_str()] = json!(u);
+ }
+ let images: Vec<&String> = media.iter().filter(|(n, _)| n != "mask").map(|(_, u)| u).collect();
if images.is_empty() {
return b;
}
@@ -157,6 +163,16 @@ pub fn body(inputs: &serde_json::Map<String, J>, media: &[(String, String)], fie
mod tests {
use super::*;
+ #[test]
+ fn a_mask_goes_to_the_mask_field() {
+ let fields = vec![("image_url".to_string(), false), ("mask_url".to_string(), false), ("prompt".to_string(), false)];
+ let media = vec![("image".to_string(), "https://f/pic.png".to_string()), ("mask".to_string(), "https://f/mask.png".to_string())];
+ let b = body(&serde_json::Map::new(), &media, &fields);
+ assert_eq!(b["image_url"], json!("https://f/pic.png"));
+ assert_eq!(b["mask_url"], json!("https://f/mask.png"));
+ assert!(b.get("image_urls").is_none());
+ }
+
#[test]
fn settings_the_schema_names_go_through() {
let inputs = json!({"prompt": "a face", "seed": 7, "resolution": "4K", "aspect_ratio": "1:1", "image": "x", "x_safety_tolerance": "4"});