Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- index.html +20 -5
index.html
CHANGED
|
@@ -75,6 +75,22 @@ $("threshold").addEventListener("input", e => { $("threshold_v").textContent = e
|
|
| 75 |
|
| 76 |
function setStatus(t){ $("status").textContent = t; }
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
async function init(){
|
| 79 |
try {
|
| 80 |
setStatus("Pyodide load ho raha hai…");
|
|
@@ -112,14 +128,13 @@ const PY_RUN = [
|
|
| 112 |
].join("\n");
|
| 113 |
|
| 114 |
async function convert(){
|
| 115 |
-
|
| 116 |
-
if(
|
| 117 |
$("convert").disabled = true;
|
| 118 |
$("convert").textContent = "Converting… (20–60s)";
|
| 119 |
setStatus("Convert ho raha hai… slow but accurate, intezar karo.");
|
| 120 |
try {
|
| 121 |
-
|
| 122 |
-
pyodide.FS.writeFile("/input.png", buf);
|
| 123 |
pyodide.globals.set("TH", $("threshold").value);
|
| 124 |
pyodide.globals.set("Q", $("quality").value.replace("x",""));
|
| 125 |
pyodide.globals.set("SM", $("smoothing").value);
|
|
@@ -158,7 +173,7 @@ $("download").addEventListener("click", () => {
|
|
| 158 |
const blob = new Blob([lastSvg], {type: "image/svg+xml"});
|
| 159 |
const a = document.createElement("a");
|
| 160 |
a.href = URL.createObjectURL(blob);
|
| 161 |
-
a.download = "
|
| 162 |
a.click();
|
| 163 |
setTimeout(() => URL.revokeObjectURL(a.href), 5000);
|
| 164 |
});
|
|
|
|
| 75 |
|
| 76 |
function setStatus(t){ $("status").textContent = t; }
|
| 77 |
|
| 78 |
+
// File ko select hote hi memory me parh lo — taake dobara convert par
|
| 79 |
+
// browser ki file-reference expire na ho ("could not be read" error fix).
|
| 80 |
+
let fileBytes = null, fileName = "icon";
|
| 81 |
+
$("file").addEventListener("change", async (e) => {
|
| 82 |
+
const f = e.target.files[0];
|
| 83 |
+
fileBytes = null;
|
| 84 |
+
if(!f) return;
|
| 85 |
+
try {
|
| 86 |
+
fileBytes = new Uint8Array(await f.arrayBuffer());
|
| 87 |
+
fileName = (f.name || "icon").replace(/\.[^.]+$/, "");
|
| 88 |
+
setStatus("File ready: " + f.name + " — Convert dabao.");
|
| 89 |
+
} catch(err){
|
| 90 |
+
setStatus("File parh nahi saki, dobara select karo.");
|
| 91 |
+
}
|
| 92 |
+
});
|
| 93 |
+
|
| 94 |
async function init(){
|
| 95 |
try {
|
| 96 |
setStatus("Pyodide load ho raha hai…");
|
|
|
|
| 128 |
].join("\n");
|
| 129 |
|
| 130 |
async function convert(){
|
| 131 |
+
if(!fileBytes){ setStatus("Pehle image select karo (dobara select karo agar error aaye)."); return; }
|
| 132 |
+
if($("convert").disabled) return;
|
| 133 |
$("convert").disabled = true;
|
| 134 |
$("convert").textContent = "Converting… (20–60s)";
|
| 135 |
setStatus("Convert ho raha hai… slow but accurate, intezar karo.");
|
| 136 |
try {
|
| 137 |
+
pyodide.FS.writeFile("/input.png", fileBytes);
|
|
|
|
| 138 |
pyodide.globals.set("TH", $("threshold").value);
|
| 139 |
pyodide.globals.set("Q", $("quality").value.replace("x",""));
|
| 140 |
pyodide.globals.set("SM", $("smoothing").value);
|
|
|
|
| 173 |
const blob = new Blob([lastSvg], {type: "image/svg+xml"});
|
| 174 |
const a = document.createElement("a");
|
| 175 |
a.href = URL.createObjectURL(blob);
|
| 176 |
+
a.download = fileName + ".svg";
|
| 177 |
a.click();
|
| 178 |
setTimeout(() => URL.revokeObjectURL(a.href), 5000);
|
| 179 |
});
|