Spaces:
Running
Running
Force square for model P
Browse files- dist/index.cjs +26 -16
- dist/index.js +26 -16
dist/index.cjs
CHANGED
@@ -1120,7 +1120,7 @@ var TrustMark = class _TrustMark {
|
|
1120 |
await sleep(0);
|
1121 |
start_time = /* @__PURE__ */ new Date();
|
1122 |
let tf_merge = tf.clipByValue(tf.add(tf_residual.mul(wm_strength), cover_image.tf_crop), 0, 1);
|
1123 |
-
if (cover_image.aspect_ratio > 2) {
|
1124 |
if (cover_image.orientation == "landscape") {
|
1125 |
const axe_length = Math.floor((cover_image.width - cover_image.crop_axe) / 2);
|
1126 |
const part_a = cover_image.tf_source.slice([0, 0, 0], [cover_image.crop_axe, axe_length, 3]);
|
@@ -1167,10 +1167,12 @@ var TrustMark = class _TrustMark {
|
|
1167 |
};
|
1168 |
}
|
1169 |
/**
|
1170 |
-
* Processes
|
1171 |
*
|
1172 |
-
* @param image The
|
1173 |
-
* @
|
|
|
|
|
1174 |
*/
|
1175 |
async processImage(image2, process_type) {
|
1176 |
const start_time = /* @__PURE__ */ new Date();
|
@@ -1183,7 +1185,7 @@ var TrustMark = class _TrustMark {
|
|
1183 |
image2.orientation = "portrait";
|
1184 |
image2.aspect_ratio = image2.height / image2.width;
|
1185 |
}
|
1186 |
-
if (image2.aspect_ratio > ASPECT_RATIO_LIM) {
|
1187 |
const size = Math.min(image2.width, image2.height);
|
1188 |
const left = (image2.width - size) / 2;
|
1189 |
const top = (image2.height - size) / 2;
|
@@ -1217,10 +1219,12 @@ var TrustMark = class _TrustMark {
|
|
1217 |
return image2;
|
1218 |
}
|
1219 |
/**
|
1220 |
-
* Loads an image from a
|
1221 |
*
|
1222 |
-
* @param image_url The URL of the image to
|
1223 |
-
* @
|
|
|
|
|
1224 |
*/
|
1225 |
async loadImage(image_url, process_type) {
|
1226 |
return new Promise(async (resolve) => {
|
@@ -1247,7 +1251,10 @@ var TrustMark = class _TrustMark {
|
|
1247 |
});
|
1248 |
}
|
1249 |
/**
|
1250 |
-
* Loads the
|
|
|
|
|
|
|
1251 |
*/
|
1252 |
async loadModels(type = "Q") {
|
1253 |
const models = await getModels();
|
@@ -1261,14 +1268,18 @@ var TrustMark = class _TrustMark {
|
|
1261 |
if (type == "P") {
|
1262 |
decoder_model_url = models["decoder_P.onnx"];
|
1263 |
encoder_model_url = models["encoder_P.onnx"];
|
1264 |
-
this.preprocess_224_session = await ort.InferenceSession.create("models/preprocess_224.onnx").catch(
|
1265 |
-
|
1266 |
-
|
|
|
|
|
1267 |
}
|
1268 |
const session_option = { executionProviders: ["cpu"] };
|
1269 |
-
this.preprocess_256_session = await ort.InferenceSession.create("models/preprocess_256.onnx").catch(
|
1270 |
-
|
1271 |
-
|
|
|
|
|
1272 |
this.decoder_session = await ort.InferenceSession.create(decoder_model_url, session_option).catch((error) => {
|
1273 |
throw new Error(`Error loading decoder ONNX model: ${error}`);
|
1274 |
});
|
@@ -1414,7 +1425,6 @@ async function hash(content) {
|
|
1414 |
const hashBuffer = await crypto.subtle.digest("SHA-256", content);
|
1415 |
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
1416 |
const hashHex = hashArray.map((bytes) => bytes.toString(16).padStart(2, "0")).join("");
|
1417 |
-
console.log(hashHex);
|
1418 |
return hashHex;
|
1419 |
}
|
1420 |
// Annotate the CommonJS export names for ESM import in node:
|
|
|
1120 |
await sleep(0);
|
1121 |
start_time = /* @__PURE__ */ new Date();
|
1122 |
let tf_merge = tf.clipByValue(tf.add(tf_residual.mul(wm_strength), cover_image.tf_crop), 0, 1);
|
1123 |
+
if (cover_image.aspect_ratio > 2 || this.model_type == "P") {
|
1124 |
if (cover_image.orientation == "landscape") {
|
1125 |
const axe_length = Math.floor((cover_image.width - cover_image.crop_axe) / 2);
|
1126 |
const part_a = cover_image.tf_source.slice([0, 0, 0], [cover_image.crop_axe, axe_length, 3]);
|
|
|
1167 |
};
|
1168 |
}
|
1169 |
/**
|
1170 |
+
* Processes the input image based on the specified processing type.
|
1171 |
*
|
1172 |
+
* @param {any} image - The image object containing the tensor source and other properties.
|
1173 |
+
* @param {string} process_type - The type of processing to be applied to the image ('decode' or other types).
|
1174 |
+
* @returns {Promise<any>} A promise that resolves with the processed image.
|
1175 |
+
* @throws {Error} Throws an error if there is an issue processing the image.
|
1176 |
*/
|
1177 |
async processImage(image2, process_type) {
|
1178 |
const start_time = /* @__PURE__ */ new Date();
|
|
|
1185 |
image2.orientation = "portrait";
|
1186 |
image2.aspect_ratio = image2.height / image2.width;
|
1187 |
}
|
1188 |
+
if (image2.aspect_ratio > ASPECT_RATIO_LIM || this.model_type == "P") {
|
1189 |
const size = Math.min(image2.width, image2.height);
|
1190 |
const left = (image2.width - size) / 2;
|
1191 |
const top = (image2.height - size) / 2;
|
|
|
1219 |
return image2;
|
1220 |
}
|
1221 |
/**
|
1222 |
+
* Loads an image from a URL or filesystem and processes it based on the specified type.
|
1223 |
*
|
1224 |
+
* @param {string} image_url - The URL or filesystem path of the image to be loaded.
|
1225 |
+
* @param {string} process_type - The type of processing to be applied to the image.
|
1226 |
+
* @returns {Promise<any>} A promise that resolves with the processed image.
|
1227 |
+
* @throws {Error} Throws an error if there is an issue loading or processing the image.
|
1228 |
*/
|
1229 |
async loadImage(image_url, process_type) {
|
1230 |
return new Promise(async (resolve) => {
|
|
|
1251 |
});
|
1252 |
}
|
1253 |
/**
|
1254 |
+
* Loads the necessary models based on the specified type.
|
1255 |
+
*
|
1256 |
+
* @param {string} [type='Q'] - The type of models to load ('Q' or 'P').
|
1257 |
+
* @throws {Error} Throws an error if there is an issue loading any of the models.
|
1258 |
*/
|
1259 |
async loadModels(type = "Q") {
|
1260 |
const models = await getModels();
|
|
|
1268 |
if (type == "P") {
|
1269 |
decoder_model_url = models["decoder_P.onnx"];
|
1270 |
encoder_model_url = models["encoder_P.onnx"];
|
1271 |
+
this.preprocess_224_session = await ort.InferenceSession.create("models/preprocess_224.onnx").catch(
|
1272 |
+
(error) => {
|
1273 |
+
throw new Error(`Error loading preprocessing ONNX model: ${error}`);
|
1274 |
+
}
|
1275 |
+
);
|
1276 |
}
|
1277 |
const session_option = { executionProviders: ["cpu"] };
|
1278 |
+
this.preprocess_256_session = await ort.InferenceSession.create("models/preprocess_256.onnx").catch(
|
1279 |
+
(error) => {
|
1280 |
+
throw new Error(`Error loading preprocessing ONNX model: ${error}`);
|
1281 |
+
}
|
1282 |
+
);
|
1283 |
this.decoder_session = await ort.InferenceSession.create(decoder_model_url, session_option).catch((error) => {
|
1284 |
throw new Error(`Error loading decoder ONNX model: ${error}`);
|
1285 |
});
|
|
|
1425 |
const hashBuffer = await crypto.subtle.digest("SHA-256", content);
|
1426 |
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
1427 |
const hashHex = hashArray.map((bytes) => bytes.toString(16).padStart(2, "0")).join("");
|
|
|
1428 |
return hashHex;
|
1429 |
}
|
1430 |
// Annotate the CommonJS export names for ESM import in node:
|
dist/index.js
CHANGED
@@ -1080,7 +1080,7 @@ var TrustMark = class _TrustMark {
|
|
1080 |
await sleep(0);
|
1081 |
start_time = /* @__PURE__ */ new Date();
|
1082 |
let tf_merge = tf.clipByValue(tf.add(tf_residual.mul(wm_strength), cover_image.tf_crop), 0, 1);
|
1083 |
-
if (cover_image.aspect_ratio > 2) {
|
1084 |
if (cover_image.orientation == "landscape") {
|
1085 |
const axe_length = Math.floor((cover_image.width - cover_image.crop_axe) / 2);
|
1086 |
const part_a = cover_image.tf_source.slice([0, 0, 0], [cover_image.crop_axe, axe_length, 3]);
|
@@ -1127,10 +1127,12 @@ var TrustMark = class _TrustMark {
|
|
1127 |
};
|
1128 |
}
|
1129 |
/**
|
1130 |
-
* Processes
|
1131 |
*
|
1132 |
-
* @param image The
|
1133 |
-
* @
|
|
|
|
|
1134 |
*/
|
1135 |
async processImage(image2, process_type) {
|
1136 |
const start_time = /* @__PURE__ */ new Date();
|
@@ -1143,7 +1145,7 @@ var TrustMark = class _TrustMark {
|
|
1143 |
image2.orientation = "portrait";
|
1144 |
image2.aspect_ratio = image2.height / image2.width;
|
1145 |
}
|
1146 |
-
if (image2.aspect_ratio > ASPECT_RATIO_LIM) {
|
1147 |
const size = Math.min(image2.width, image2.height);
|
1148 |
const left = (image2.width - size) / 2;
|
1149 |
const top = (image2.height - size) / 2;
|
@@ -1177,10 +1179,12 @@ var TrustMark = class _TrustMark {
|
|
1177 |
return image2;
|
1178 |
}
|
1179 |
/**
|
1180 |
-
* Loads an image from a
|
1181 |
*
|
1182 |
-
* @param image_url The URL of the image to
|
1183 |
-
* @
|
|
|
|
|
1184 |
*/
|
1185 |
async loadImage(image_url, process_type) {
|
1186 |
return new Promise(async (resolve) => {
|
@@ -1207,7 +1211,10 @@ var TrustMark = class _TrustMark {
|
|
1207 |
});
|
1208 |
}
|
1209 |
/**
|
1210 |
-
* Loads the
|
|
|
|
|
|
|
1211 |
*/
|
1212 |
async loadModels(type = "Q") {
|
1213 |
const models = await getModels();
|
@@ -1221,14 +1228,18 @@ var TrustMark = class _TrustMark {
|
|
1221 |
if (type == "P") {
|
1222 |
decoder_model_url = models["decoder_P.onnx"];
|
1223 |
encoder_model_url = models["encoder_P.onnx"];
|
1224 |
-
this.preprocess_224_session = await ort.InferenceSession.create("models/preprocess_224.onnx").catch(
|
1225 |
-
|
1226 |
-
|
|
|
|
|
1227 |
}
|
1228 |
const session_option = { executionProviders: ["cpu"] };
|
1229 |
-
this.preprocess_256_session = await ort.InferenceSession.create("models/preprocess_256.onnx").catch(
|
1230 |
-
|
1231 |
-
|
|
|
|
|
1232 |
this.decoder_session = await ort.InferenceSession.create(decoder_model_url, session_option).catch((error) => {
|
1233 |
throw new Error(`Error loading decoder ONNX model: ${error}`);
|
1234 |
});
|
@@ -1374,7 +1385,6 @@ async function hash(content) {
|
|
1374 |
const hashBuffer = await crypto.subtle.digest("SHA-256", content);
|
1375 |
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
1376 |
const hashHex = hashArray.map((bytes) => bytes.toString(16).padStart(2, "0")).join("");
|
1377 |
-
console.log(hashHex);
|
1378 |
return hashHex;
|
1379 |
}
|
1380 |
export {
|
|
|
1080 |
await sleep(0);
|
1081 |
start_time = /* @__PURE__ */ new Date();
|
1082 |
let tf_merge = tf.clipByValue(tf.add(tf_residual.mul(wm_strength), cover_image.tf_crop), 0, 1);
|
1083 |
+
if (cover_image.aspect_ratio > 2 || this.model_type == "P") {
|
1084 |
if (cover_image.orientation == "landscape") {
|
1085 |
const axe_length = Math.floor((cover_image.width - cover_image.crop_axe) / 2);
|
1086 |
const part_a = cover_image.tf_source.slice([0, 0, 0], [cover_image.crop_axe, axe_length, 3]);
|
|
|
1127 |
};
|
1128 |
}
|
1129 |
/**
|
1130 |
+
* Processes the input image based on the specified processing type.
|
1131 |
*
|
1132 |
+
* @param {any} image - The image object containing the tensor source and other properties.
|
1133 |
+
* @param {string} process_type - The type of processing to be applied to the image ('decode' or other types).
|
1134 |
+
* @returns {Promise<any>} A promise that resolves with the processed image.
|
1135 |
+
* @throws {Error} Throws an error if there is an issue processing the image.
|
1136 |
*/
|
1137 |
async processImage(image2, process_type) {
|
1138 |
const start_time = /* @__PURE__ */ new Date();
|
|
|
1145 |
image2.orientation = "portrait";
|
1146 |
image2.aspect_ratio = image2.height / image2.width;
|
1147 |
}
|
1148 |
+
if (image2.aspect_ratio > ASPECT_RATIO_LIM || this.model_type == "P") {
|
1149 |
const size = Math.min(image2.width, image2.height);
|
1150 |
const left = (image2.width - size) / 2;
|
1151 |
const top = (image2.height - size) / 2;
|
|
|
1179 |
return image2;
|
1180 |
}
|
1181 |
/**
|
1182 |
+
* Loads an image from a URL or filesystem and processes it based on the specified type.
|
1183 |
*
|
1184 |
+
* @param {string} image_url - The URL or filesystem path of the image to be loaded.
|
1185 |
+
* @param {string} process_type - The type of processing to be applied to the image.
|
1186 |
+
* @returns {Promise<any>} A promise that resolves with the processed image.
|
1187 |
+
* @throws {Error} Throws an error if there is an issue loading or processing the image.
|
1188 |
*/
|
1189 |
async loadImage(image_url, process_type) {
|
1190 |
return new Promise(async (resolve) => {
|
|
|
1211 |
});
|
1212 |
}
|
1213 |
/**
|
1214 |
+
* Loads the necessary models based on the specified type.
|
1215 |
+
*
|
1216 |
+
* @param {string} [type='Q'] - The type of models to load ('Q' or 'P').
|
1217 |
+
* @throws {Error} Throws an error if there is an issue loading any of the models.
|
1218 |
*/
|
1219 |
async loadModels(type = "Q") {
|
1220 |
const models = await getModels();
|
|
|
1228 |
if (type == "P") {
|
1229 |
decoder_model_url = models["decoder_P.onnx"];
|
1230 |
encoder_model_url = models["encoder_P.onnx"];
|
1231 |
+
this.preprocess_224_session = await ort.InferenceSession.create("models/preprocess_224.onnx").catch(
|
1232 |
+
(error) => {
|
1233 |
+
throw new Error(`Error loading preprocessing ONNX model: ${error}`);
|
1234 |
+
}
|
1235 |
+
);
|
1236 |
}
|
1237 |
const session_option = { executionProviders: ["cpu"] };
|
1238 |
+
this.preprocess_256_session = await ort.InferenceSession.create("models/preprocess_256.onnx").catch(
|
1239 |
+
(error) => {
|
1240 |
+
throw new Error(`Error loading preprocessing ONNX model: ${error}`);
|
1241 |
+
}
|
1242 |
+
);
|
1243 |
this.decoder_session = await ort.InferenceSession.create(decoder_model_url, session_option).catch((error) => {
|
1244 |
throw new Error(`Error loading decoder ONNX model: ${error}`);
|
1245 |
});
|
|
|
1385 |
const hashBuffer = await crypto.subtle.digest("SHA-256", content);
|
1386 |
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
1387 |
const hashHex = hashArray.map((bytes) => bytes.toString(16).padStart(2, "0")).join("");
|
|
|
1388 |
return hashHex;
|
1389 |
}
|
1390 |
export {
|