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-app-motion: raea motion and raea setup motion leave raea-app-tools, and kimodo's torch path passes L1

shinyobjectzc37616685c7c
diff --git a/Cargo.lock b/Cargo.lock
index 5bb8db3b..2c3591ff 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -13904,6 +13904,16 @@ dependencies = [
"serde_json",
]
+[[package]]
+name = "raea-app-motion"
+version = "0.1.0"
+dependencies = [
+ "raea-io-home",
+ "raea-runtime-bundle",
+ "raea-sys-kimodo",
+ "serde_json",
+]
+
[[package]]
name = "raea-app-notes"
version = "0.1.0"
@@ -13986,13 +13996,13 @@ name = "raea-app-tools"
version = "0.1.0"
dependencies = [
"dunce",
+ "raea-app-motion",
"raea-io-assets",
"raea-io-gen",
"raea-io-home",
"raea-io-media",
"raea-runtime-bundle",
"raea-runtime-export",
- "raea-sys-kimodo",
"serde_json",
]
@@ -15991,6 +16001,7 @@ name = "raea-sys-kimodo"
version = "0.1.0"
dependencies = [
"anyhow",
+ "dunce",
"mlx-rs",
"raea-io-home",
"raea-sys-ml",
diff --git a/Cargo.toml b/Cargo.toml
index 52497e89..2397ec17 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -194,6 +194,7 @@ members = [
"apps/workspace/registry",
"apps/ci",
"apps/tools",
+ "apps/motion",
"apps/engines",
"apps/interchange",
"apps/judge",
diff --git a/apps/motion/Cargo.toml b/apps/motion/Cargo.toml
new file mode 100644
index 00000000..60894124
--- /dev/null
+++ b/apps/motion/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "raea-app-motion"
+version = "0.1.0"
+edition = "2024"
+license = "FSL-1.1-ALv2"
+publish = false
+description = "`raea motion` and `raea setup motion`: body motion made by Kimodo on this machine, on MLX on a Mac, on PyTorch elsewhere"
+
+[dependencies]
+# raea's models folder, where the models and the PyTorch environment go
+raea-io-home = { path = "../../io/home" }
+serde_json = "1"
+# the verbs' flags read as a render reads its own
+raea-runtime-bundle = { path = "../../runtime/bundle" }
+# Kimodo on MLX on a Mac, on PyTorch elsewhere (raea-sys-kimodo's torch.rs, plain Rust that runs the environment it makes)
+raea-sys-kimodo = { path = "../../systems/kimodo" }
diff --git a/apps/tools/src/motion.rs b/apps/motion/src/lib.rs
similarity index 96%
rename from apps/tools/src/motion.rs
rename to apps/motion/src/lib.rs
index a74925d8..4333e634 100644
--- a/apps/tools/src/motion.rs
+++ b/apps/motion/src/lib.rs
@@ -111,7 +111,7 @@ fn make(ask: Ask) -> R<String> {
let keys = ask.keys.as_ref().map(std::path::Path::new);
let job = torch::Job { line: &ask.words, frames: ask.frames, seed: ask.seed, steps: ask.steps, keys, cfg: (2.0, 2.0) };
let made = t.make(&job).map_err(|e| format!("raea motion: {e}"))?;
- let (stats, sk) = (Stats::load(&t.checkpoint()).map_err(|e| format!("raea motion: {e}"))?, Skeleton::soma().map_err(|e| format!("raea motion: {e}"))?);
+ let (stats, sk) = (Stats::load(&t.checkpoint).map_err(|e| format!("raea motion: {e}"))?, Skeleton::soma().map_err(|e| format!("raea motion: {e}"))?);
let motion = decode::decode(&made.features, &stats, &sk);
let info = &made.info;
let clean = info["line"].as_str().unwrap_or(&ask.words).to_string();
@@ -185,11 +185,9 @@ fn fetching() -> impl FnMut(&str, u64) {
}
}
-/// What a folder takes on disk, as du says it (through a link: the Mac's model folders can be links to their files)
+/// What a folder takes on disk, through a link (the Mac's model folders can be links to their files).
fn disk(dir: &std::path::Path) -> String {
- std::process::Command::new("du").arg("-shL").arg(dir).output().ok()
- .and_then(|o| String::from_utf8_lossy(&o.stdout).split_whitespace().next().map(str::to_string))
- .unwrap_or_else(|| "?".into())
+ raea_io_home::disk_use(dir, true)
}
/// `raea setup motion [--check]`: what raea motion runs on here, made where missing (--check only says), and where it is.
diff --git a/apps/tools/Cargo.toml b/apps/tools/Cargo.toml
index 3a516779..7cde5840 100644
--- a/apps/tools/Cargo.toml
+++ b/apps/tools/Cargo.toml
@@ -17,6 +17,5 @@ serde_json = "1"
# the verbs' flags read as a render reads its own
raea-runtime-bundle = { path = "../../runtime/bundle" }
raea-runtime-export = { path = "../../runtime/export" }
-# `raea motion` and `raea setup motion`: Kimodo on MLX on a Mac, on PyTorch elsewhere (raea-sys-kimodo's torch.rs, plain
-# Rust that runs the environment it makes)
-raea-sys-kimodo = { path = "../../systems/kimodo" }
+# `raea motion` and `raea setup motion` (apps/motion), still reached as tools::motion
+raea-app-motion = { path = "../motion" }
diff --git a/apps/tools/src/lib.rs b/apps/tools/src/lib.rs
index 643eed89..3965b53a 100644
--- a/apps/tools/src/lib.rs
+++ b/apps/tools/src/lib.rs
@@ -4,8 +4,8 @@
//! made.app, fal, Replicate, OpenRouter, Modal and ComfyUI, with sao as the local model: apps/tools/src/generate.rs).
pub mod generate;
-/// `raea motion` and `raea setup motion`: body motion made by Kimodo, on MLX on a Mac, on PyTorch elsewhere (raea-sys-kimodo)
-pub mod motion;
+/// `raea motion` and `raea setup motion`: body motion made by Kimodo, on MLX on a Mac, on PyTorch elsewhere (apps/motion)
+pub use raea_app_motion as motion;
pub mod song;
pub mod sound;
pub mod splat;
diff --git a/apps/tools/src/sound.rs b/apps/tools/src/sound.rs
index 7cb2010d..502339ec 100644
--- a/apps/tools/src/sound.rs
+++ b/apps/tools/src/sound.rs
@@ -259,11 +259,9 @@ pub fn setup_audio(args: &[String]) -> R<String> {
Ok(format!("{head}\n{}", lines.join("\n")))
}
-/// What a folder takes on disk, as du says it (clones of another install count in full here, as du counts them).
+/// What a folder takes on disk (clones of another install count in full here, as du counts them).
fn disk(dir: &Path) -> String {
- std::process::Command::new("du").arg("-sh").arg(dir).output().ok()
- .and_then(|o| String::from_utf8_lossy(&o.stdout).split_whitespace().next().map(str::to_string))
- .unwrap_or_else(|| "?".into())
+ raea_io_home::disk_use(dir, false)
}
// ---- the open sample libraries --------------------------------------------------------------------------------------
diff --git a/io/home/src/lib.rs b/io/home/src/lib.rs
index fe2373d1..0d5d816e 100644
--- a/io/home/src/lib.rs
+++ b/io/home/src/lib.rs
@@ -3,6 +3,12 @@
pub mod sdk;
+/// What a folder takes on disk, as `du -sh` says it (`links`: through a link to its files), or "?".
+pub fn disk_use(dir: &std::path::Path, links: bool) -> String {
+ let o = std::process::Command::new("du").arg(if links { "-shL" } else { "-sh" }).arg(dir).output();
+ o.ok().and_then(|o| String::from_utf8_lossy(&o.stdout).split_whitespace().next().map(str::to_string)).unwrap_or_else(|| "?".into())
+}
+
/// Where raea's own files are (the SDK's TypeScript, the lite runtime and its packages, the shell's sources, the
/// sandbox's modules, the tools that install the local models): $RAEA_HOME; else beside an installed binary,
/// `<prefix>/share/raea` for `<prefix>/bin/raea` (the release's layout, tools/release.sh); else the tree this
diff --git a/systems/kimodo/Cargo.toml b/systems/kimodo/Cargo.toml
index 29fc691a..7708dbaa 100644
--- a/systems/kimodo/Cargo.toml
+++ b/systems/kimodo/Cargo.toml
@@ -7,6 +7,8 @@ description = "Kimodo (nv-tlabs/kimodo) on raea's MLX facility: SOMA body motion
license = "FSL-1.1-ALv2"
[dependencies]
+# a path handed to Python without Windows' \\?\ prefix
+dunce = "1"
anyhow = "1"
serde_json = "1"
diff --git a/systems/kimodo/src/torch.rs b/systems/kimodo/src/torch.rs
index bb014363..af3404ab 100644
--- a/systems/kimodo/src/torch.rs
+++ b/systems/kimodo/src/torch.rs
@@ -50,6 +50,10 @@ const NEEDS: &[(&str, &str)] = &[
/// Kimodo's PyTorch environment in a folder (raea's models folder's kimodo-torch).
pub struct Torch {
pub dir: PathBuf,
+ /// the Python environment
+ pub venv: PathBuf,
+ /// the motion checkpoint's folder (its stats are decode.rs's too)
+ pub checkpoint: PathBuf,
}
/// One clip asked of PyTorch.
@@ -72,25 +76,16 @@ pub struct Made {
impl Torch {
pub fn at(dir: PathBuf) -> Self {
- Torch { dir }
- }
-
- pub fn venv(&self) -> PathBuf {
- self.dir.join("venv")
+ Torch { venv: dir.join("venv"), checkpoint: dir.join("checkpoints").join("Kimodo-SOMA-RP-v1"), dir }
}
pub fn python(&self) -> PathBuf {
- if cfg!(windows) { self.venv().join("Scripts").join("python.exe") } else { self.venv().join("bin").join("python") }
- }
-
- /// the motion checkpoint's folder (its stats are decode.rs's too)
- pub fn checkpoint(&self) -> PathBuf {
- self.dir.join("checkpoints").join("Kimodo-SOMA-RP-v1")
+ if cfg!(windows) { self.venv.join("Scripts").join("python.exe") } else { self.venv.join("bin").join("python") }
}
/// the environment's record of what it was made from: a different list makes it again
fn made_from(&self) -> PathBuf {
- self.venv().join("raea-packages.txt")
+ self.venv.join("raea-packages.txt")
}
fn packages() -> String {
@@ -138,7 +133,7 @@ impl Torch {
"raea setup motion makes its Python environment with uv, which isn't on PATH: install it (https://docs.astral.sh/uv; Linux and macOS: curl -LsSf https://astral.sh/uv/install.sh | sh; Windows: winget install astral-sh.uv), then run raea setup motion again"
);
}
- let venv = self.venv();
+ let venv = self.venv.clone();
let _ = std::fs::remove_dir_all(&venv);
say(&format!("making the Python environment (Python 3.11 by uv) in {}", venv.display()));
run(Command::new("uv").args(["venv", "--quiet", "--python", "3.11"]).arg(&venv), "uv venv")?;
@@ -177,10 +172,10 @@ impl Torch {
/// One clip's features from PyTorch. The runner's progress goes to stderr as it comes.
pub fn make(&self, job: &Job) -> Result<Made> {
let runner = self.runner()?;
- let tmp = std::env::temp_dir().join(format!("raea-motion-{}", std::process::id()));
+ let tmp = std::env::temp_dir().join(format!("raea-kimodo-{}", std::process::id()));
std::fs::create_dir_all(&tmp)?;
let (ask, out) = (tmp.join("ask.json"), tmp.join("features.f32"));
- let keys = job.keys.map(|k| std::fs::canonicalize(k).unwrap_or_else(|_| k.to_path_buf()));
+ let keys = job.keys.map(|k| dunce::canonicalize(k).unwrap_or_else(|_| k.to_path_buf()));
let a = serde_json::json!({"line": job.line, "frames": job.frames, "seed": job.seed, "steps": job.steps, "keys": keys, "cfg": [job.cfg.0, job.cfg.1]});
std::fs::write(&ask, a.to_string())?;
let o = Command::new(self.python()).arg("-I").arg(&runner).arg("make").arg(&self.dir).arg(&ask).arg(&out).stderr(Stdio::inherit()).output().context("can't run the environment's Python");
@@ -219,7 +214,7 @@ pub fn root_gap(torch_root: &serde_json::Value, ours: &[[f32; 3]]) -> Option<f64
let r = torch_root.as_array()?;
(r.len() == ours.len()).then_some(())?;
r.iter().zip(ours).map(|(a, b)| {
- let a: Vec<f64> = a.as_array().map(|v| v.iter().filter_map(serde_json::Value::as_f64).collect()).unwrap_or_default();
+ let a: Vec<f64> = a.as_array().into_iter().flatten().filter_map(serde_json::Value::as_f64).collect();
(0..3).map(|i| (a.get(i).copied().unwrap_or(f64::NAN) - b[i] as f64).powi(2)).sum::<f64>().sqrt()
}).try_fold(0.0f64, |m, d| d.is_finite().then_some(m.max(d)))
}
diff --git a/tools/layers.toml b/tools/layers.toml
index d2ec5f4b..3a73668e 100644
--- a/tools/layers.toml
+++ b/tools/layers.toml
@@ -184,6 +184,7 @@ raea-app-fingerprint = "apps"
raea-app-sound = "apps"
raea-app-ci = "apps"
raea-app-tools = "apps"
+raea-app-motion = "apps"
raea-app-engines = "apps"
raea-app-interchange = "apps"
raea-app-judge = "apps"