File size: 1,181 Bytes
0473e83 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
async function shareToCommunity(ele, canvasID) {
ele.disabled = true;
const canvas = document.getElementById(canvasID);
const canvasBlob = await new Promise((resolve) =>
canvas.toBlob(resolve, "image/png")
);
const fileName = `share-${Date.now()}.png`;
const canvasFile = new File([canvasBlob], fileName, {
type: "image/png",
});
const imageUrl = await uploadFile(canvasFile);
const title = "Candle + YOLOv8";
const descriptionMd = `<img src="${imageUrl}">
YOLOv8 with [Candle](https://github.com/huggingface/candle)`;
const params = new URLSearchParams({
title: title,
description: descriptionMd,
preview: true,
});
window.open(
`https://huggingface.co/spaces/lmz/candle-yolo/discussions/new?${params}`,
"_blank"
);
ele.disabled = false;
}
async function uploadFile(file) {
const UPLOAD_URL = "https://huggingface.co/uploads";
const response = await fetch(UPLOAD_URL, {
method: "POST",
headers: {
"Content-Type": file.type,
"X-Requested-With": "XMLHttpRequest",
},
body: file,
});
const url = await response.text();
return url;
}
globalThis.shareToCommunity = shareToCommunity;
|