mirror of
https://github.com/huggingface/candle.git
synced 2025-06-18 19:47:12 +00:00
Update README + SAM (#866)
* use serde-wasm-bindgen, faster serialization * update readme with demos
This commit is contained in:
@ -27,3 +27,4 @@ serde_json = { workspace = true }
|
||||
# Wasm specific crates.
|
||||
console_error_panic_hook = "0.1.7"
|
||||
wasm-bindgen = "0.2.87"
|
||||
serde-wasm-bindgen = "0.6.0"
|
||||
|
@ -141,8 +141,7 @@ self.addEventListener("message", async (event) => {
|
||||
}
|
||||
|
||||
self.postMessage({ status: "segmenting", message: "Segmenting" });
|
||||
const result = sam.mask_for_point(points.x, points.y);
|
||||
const { mask, image } = JSON.parse(result);
|
||||
const { mask, image } = sam.mask_for_point(points.x, points.y);
|
||||
const maskDataURL = await createImageCanvas(mask, image);
|
||||
// Send the segment back to the main thread as JSON
|
||||
self.postMessage({
|
||||
|
@ -76,7 +76,7 @@ impl Model {
|
||||
}
|
||||
|
||||
// x and y have to be between 0 and 1
|
||||
pub fn mask_for_point(&self, x: f64, y: f64) -> Result<String, JsError> {
|
||||
pub fn mask_for_point(&self, x: f64, y: f64) -> Result<JsValue, JsError> {
|
||||
if !(0. ..=1.).contains(&x) {
|
||||
Err(JsError::new(&format!(
|
||||
"x has to be between 0 and 1, got {x}"
|
||||
@ -112,8 +112,7 @@ impl Model {
|
||||
width: embeddings.width,
|
||||
height: embeddings.height,
|
||||
};
|
||||
let json = serde_json::to_string(&MaskImage { mask, image })?;
|
||||
Ok(json)
|
||||
Ok(serde_wasm_bindgen::to_value(&MaskImage { mask, image })?)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user