Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Scripts: the training kit zips its dataset in Node; generators write LF on every OS

Adarsh914a38031d49
diff --git a/scripts/gen-soul-originals.py b/scripts/gen-soul-originals.py
index a02305b3..f88da78c 100644
--- a/scripts/gen-soul-originals.py
+++ b/scripts/gen-soul-originals.py
@@ -283,7 +283,7 @@ export const SOUL_CATEGORIES: Record<"v1" | "v2", string[]> = {ts(categories)};
/** The 139 looks (106 Soul v1, 33 Soul 2.0), each a Fuobe Soul run: words, LoRAs, a grade, an overlay. */
export const SOUL_ORIGINALS: SoulLook[] = {ts(looks)};
"""
-OUT.write_text(out, encoding="utf-8")
+OUT.write_text(out, encoding="utf-8", newline="\n")
def hue(look_id):
@@ -323,5 +323,5 @@ export const SOUL_LOOK_CATEGORIES: Record<"v1" | "v2", string[]> = {ts(categorie
*/
export const SOUL_LEGACY_IDS: Record<string, string> = {ts(legacy)};
"""
-CARDS_OUT.write_text(cards_out, encoding="utf-8")
+CARDS_OUT.write_text(cards_out, encoding="utf-8", newline="\n")
print(f"wrote {len(looks)} Soul looks ({sum(1 for l in looks if l['family'] == 'v1')} v1, {sum(1 for l in looks if l['family'] == 'v2')} v2) to {OUT.relative_to(ROOT)}")
diff --git a/scripts/gen-trainers.py b/scripts/gen-trainers.py
index 82ff0e10..f69c0833 100644
--- a/scripts/gen-trainers.py
+++ b/scripts/gen-trainers.py
@@ -177,5 +177,5 @@ ts = (
"/** fal's LoRA trainers (a zip of 001.jpg + 001.txt pairs, or clips for video), with their fields, prices and licences. */\n"
f"export const HOSTED_TRAINERS: HostedTrainer[] = {json.dumps(trainers, indent=2, ensure_ascii=False)};\n"
)
-OUT.write_text(ts, encoding="utf-8")
+OUT.write_text(ts, encoding="utf-8", newline="\n")
print(f"wrote {OUT.relative_to(ROOT)}: {len(trainers)} trainers ({len(USED)} used by Soul ID)")
diff --git a/scripts/train/kit.mjs b/scripts/train/kit.mjs
index ada9f9ea..69184f90 100644
--- a/scripts/train/kit.mjs
+++ b/scripts/train/kit.mjs
@@ -20,6 +20,7 @@ import fs from "node:fs";
import { registerHooks } from "node:module";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
+import zlib from "node:zlib";
import { resolve } from "../lib/ts-paths.mjs";
@@ -54,6 +55,48 @@ const loadLog = (id) => {
return fs.existsSync(p) ? readJson(p) : { lora: id, version: 1, items: [] };
};
const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
+/** A stored zip of files in `dir`, by their names there (as `python3 -m zipfile -c` makes it, without needing Python). */
+function zipFiles(file, dir, names) {
+ const parts = [];
+ const central = [];
+ let offset = 0;
+ for (const n of names) {
+ const name = Buffer.from(n, "utf8");
+ const data = fs.readFileSync(path.join(dir, n));
+ const crc = zlib.crc32(data) >>> 0;
+ const head = Buffer.alloc(30);
+ head.writeUInt32LE(0x04034b50, 0);
+ head.writeUInt16LE(20, 4);
+ head.writeUInt16LE(0x0800, 6);
+ head.writeUInt16LE(0x21, 12); // 1980-01-01
+ head.writeUInt32LE(crc, 14);
+ head.writeUInt32LE(data.length, 18);
+ head.writeUInt32LE(data.length, 22);
+ head.writeUInt16LE(name.length, 26);
+ const entry = Buffer.alloc(46);
+ entry.writeUInt32LE(0x02014b50, 0);
+ entry.writeUInt16LE(20, 4);
+ entry.writeUInt16LE(20, 6);
+ entry.writeUInt16LE(0x0800, 8);
+ entry.writeUInt16LE(0x21, 14);
+ entry.writeUInt32LE(crc, 16);
+ entry.writeUInt32LE(data.length, 20);
+ entry.writeUInt32LE(data.length, 24);
+ entry.writeUInt16LE(name.length, 28);
+ entry.writeUInt32LE(offset, 42);
+ parts.push(head, name, data);
+ central.push(entry, name);
+ offset += 30 + name.length + data.length;
+ }
+ const dirBytes = Buffer.concat(central);
+ const end = Buffer.alloc(22);
+ end.writeUInt32LE(0x06054b50, 0);
+ end.writeUInt16LE(names.length, 8);
+ end.writeUInt16LE(names.length, 10);
+ end.writeUInt32LE(dirBytes.length, 12);
+ end.writeUInt32LE(offset, 16);
+ fs.writeFileSync(file, Buffer.concat([...parts, dirBytes, end]));
+}
function fail(msg) {
console.error(msg);
process.exit(1);
@@ -124,7 +167,7 @@ if (cmd === "list") {
// The hosted trainer gets exactly the checked files: the logged media and their captions, zipped here.
const zipFile = path.join(out, `${id}.dataset.zip`);
fs.rmSync(zipFile, { force: true });
- execFileSync("python3", ["-I", "-m", "zipfile", "-c", zipFile, ...kit.datasetZipNames(loadLog(id))], { cwd: path.resolve(dataset), stdio: "pipe" });
+ zipFiles(zipFile, path.resolve(dataset), kit.datasetZipNames(loadLog(id)));
const zipSha = sha256(zipFile);
const zip = opt("--zip-url");
if (zip) {