Spaces:
Running
Running
Commit
·
aecd865
1
Parent(s):
67401c2
Update share_btn.py
Browse files- share_btn.py +6 -12
share_btn.py
CHANGED
|
@@ -40,38 +40,32 @@ share_js = """async () => {
|
|
| 40 |
loadingIconEl.style.removeProperty('display');
|
| 41 |
|
| 42 |
var files = [];
|
|
|
|
|
|
|
| 43 |
await Promise.all(
|
| 44 |
[...imgEls].map(async (imgEl) => {
|
| 45 |
if (imgEl.offsetWidth > 50 && imgEl.offsetHeight > 50) {
|
| 46 |
const res = await fetch(imgEl.src);
|
| 47 |
const blob = await res.blob();
|
| 48 |
-
const
|
| 49 |
-
|
| 50 |
-
files.push(new File([blob], fileName, { type: 'image/
|
| 51 |
}
|
| 52 |
})
|
| 53 |
);
|
| 54 |
-
|
| 55 |
const urls = await Promise.all(files.map((f) => uploadFile(f)));
|
| 56 |
-
console.log('liuyz_1___', urls);
|
| 57 |
const htmlImgs = urls.map(url => `<img src='${url}' width='400' height='400'>`);
|
| 58 |
-
console.log('liuyz_2___');
|
| 59 |
const descriptionMd = `<div style='display: flex; flex-wrap: wrap; column-gap: 0.75rem;'>
|
| 60 |
${htmlImgs.join(`\n`)}
|
| 61 |
</div>`;
|
| 62 |
-
console.log('liuyz_3___');
|
| 63 |
const params = new URLSearchParams({
|
| 64 |
title: promptTxt,
|
| 65 |
description: descriptionMd,
|
| 66 |
});
|
| 67 |
-
console.log(`liuyz_4___${window.location.href}`);
|
| 68 |
const paramsStr = params.toString();
|
| 69 |
window.open(`https://huggingface.co/spaces/yizhangliu/ImgCleaner/discussions/new?${paramsStr}`, '_blank');
|
| 70 |
-
console.log('liuyz_5___');
|
| 71 |
shareBtnEl.style.removeProperty('pointer-events');
|
| 72 |
-
console.log('liuyz_6___');
|
| 73 |
shareIconEl.style.removeProperty('display');
|
| 74 |
-
console.log('liuyz_7___');
|
| 75 |
loadingIconEl.style.display = 'none';
|
| 76 |
-
console.log('liuyz_8___');
|
| 77 |
}"""
|
|
|
|
| 40 |
loadingIconEl.style.removeProperty('display');
|
| 41 |
|
| 42 |
var files = [];
|
| 43 |
+
var nowTime = Date.now();
|
| 44 |
+
var imgCount = 0;
|
| 45 |
await Promise.all(
|
| 46 |
[...imgEls].map(async (imgEl) => {
|
| 47 |
if (imgEl.offsetWidth > 50 && imgEl.offsetHeight > 50) {
|
| 48 |
const res = await fetch(imgEl.src);
|
| 49 |
const blob = await res.blob();
|
| 50 |
+
const fileName = `img-cleaner-${nowTime}-${imgCount}.png`;
|
| 51 |
+
imgCount += 1;
|
| 52 |
+
files.push(new File([blob], fileName, { type: 'image/png'}));
|
| 53 |
}
|
| 54 |
})
|
| 55 |
);
|
| 56 |
+
|
| 57 |
const urls = await Promise.all(files.map((f) => uploadFile(f)));
|
|
|
|
| 58 |
const htmlImgs = urls.map(url => `<img src='${url}' width='400' height='400'>`);
|
|
|
|
| 59 |
const descriptionMd = `<div style='display: flex; flex-wrap: wrap; column-gap: 0.75rem;'>
|
| 60 |
${htmlImgs.join(`\n`)}
|
| 61 |
</div>`;
|
|
|
|
| 62 |
const params = new URLSearchParams({
|
| 63 |
title: promptTxt,
|
| 64 |
description: descriptionMd,
|
| 65 |
});
|
|
|
|
| 66 |
const paramsStr = params.toString();
|
| 67 |
window.open(`https://huggingface.co/spaces/yizhangliu/ImgCleaner/discussions/new?${paramsStr}`, '_blank');
|
|
|
|
| 68 |
shareBtnEl.style.removeProperty('pointer-events');
|
|
|
|
| 69 |
shareIconEl.style.removeProperty('display');
|
|
|
|
| 70 |
loadingIconEl.style.display = 'none';
|
|
|
|
| 71 |
}"""
|