Spaces:
Runtime error
Runtime error
Update app.js
Browse files
app.js
CHANGED
|
@@ -23,7 +23,7 @@ function getConfig() {
|
|
| 23 |
|
| 24 |
function saveConfig() {
|
| 25 |
localStorage.setItem(STORAGE_KEY, JSON.stringify(getConfig()));
|
| 26 |
-
alert("
|
| 27 |
}
|
| 28 |
|
| 29 |
async function hfTextInference(model, prompt, token) {
|
|
@@ -45,8 +45,7 @@ async function hfTextInference(model, prompt, token) {
|
|
| 45 |
|
| 46 |
if (!res.ok) {
|
| 47 |
const text = await res.text();
|
| 48 |
-
|
| 49 |
-
throw new Error(`模型调用失败: ${res.status} ${text}`);
|
| 50 |
}
|
| 51 |
|
| 52 |
const data = await res.json();
|
|
@@ -65,8 +64,7 @@ async function hfGenericTask(model, prompt, token) {
|
|
| 65 |
body: JSON.stringify({ inputs: prompt })
|
| 66 |
});
|
| 67 |
const text = await res.text();
|
| 68 |
-
|
| 69 |
-
if (!res.ok) throw new Error(`任务失败: ${res.status} ${text}`);
|
| 70 |
return text;
|
| 71 |
}
|
| 72 |
|
|
@@ -75,7 +73,7 @@ async function runAction(kind) {
|
|
| 75 |
const token = config.hfToken;
|
| 76 |
|
| 77 |
if (!token) {
|
| 78 |
-
outputs[kind].textContent = "
|
| 79 |
return;
|
| 80 |
}
|
| 81 |
|
|
@@ -95,7 +93,7 @@ async function runAction(kind) {
|
|
| 95 |
faceswap: config.faceModel
|
| 96 |
};
|
| 97 |
|
| 98 |
-
outputs[kind].textContent = "
|
| 99 |
|
| 100 |
try {
|
| 101 |
if (["chat", "code", "writing"].includes(kind)) {
|
|
@@ -103,7 +101,7 @@ async function runAction(kind) {
|
|
| 103 |
outputs[kind].textContent = answer;
|
| 104 |
} else {
|
| 105 |
const answer = await hfGenericTask(modelByKind[kind], promptByKind[kind], token);
|
| 106 |
-
outputs[kind].textContent = `
|
| 107 |
}
|
| 108 |
} catch (error) {
|
| 109 |
outputs[kind].textContent = String(error);
|
|
@@ -146,21 +144,21 @@ function bindDeployCommandHelper() {
|
|
| 146 |
btn.addEventListener("click", async () => {
|
| 147 |
const spaceName = document.getElementById("spaceName").value.trim();
|
| 148 |
if (!spaceName) {
|
| 149 |
-
output.textContent = "
|
| 150 |
return;
|
| 151 |
}
|
| 152 |
|
| 153 |
const sdk = document.getElementById("spaceSdk")?.value || "static";
|
| 154 |
const privateFlag = document.getElementById("spacePrivate")?.checked ? " --private" : "";
|
| 155 |
|
| 156 |
-
const cmd = `HF_TOKEN=
|
| 157 |
output.textContent = cmd;
|
| 158 |
|
| 159 |
try {
|
| 160 |
await navigator.clipboard.writeText(cmd);
|
| 161 |
-
output.textContent += "\n\n✅
|
| 162 |
} catch {
|
| 163 |
-
output.textContent += "\n\n⚠️
|
| 164 |
}
|
| 165 |
});
|
| 166 |
}
|
|
|
|
| 23 |
|
| 24 |
function saveConfig() {
|
| 25 |
localStorage.setItem(STORAGE_KEY, JSON.stringify(getConfig()));
|
| 26 |
+
alert("Config saved to browser");
|
| 27 |
}
|
| 28 |
|
| 29 |
async function hfTextInference(model, prompt, token) {
|
|
|
|
| 45 |
|
| 46 |
if (!res.ok) {
|
| 47 |
const text = await res.text();
|
| 48 |
+
throw new Error(`Model Error: ${res.status} ${text}`);
|
|
|
|
| 49 |
}
|
| 50 |
|
| 51 |
const data = await res.json();
|
|
|
|
| 64 |
body: JSON.stringify({ inputs: prompt })
|
| 65 |
});
|
| 66 |
const text = await res.text();
|
| 67 |
+
if (!res.ok) throw new Error(`Task Error: ${res.status} ${text}`);
|
|
|
|
| 68 |
return text;
|
| 69 |
}
|
| 70 |
|
|
|
|
| 73 |
const token = config.hfToken;
|
| 74 |
|
| 75 |
if (!token) {
|
| 76 |
+
outputs[kind].textContent = "Please enter Hugging Face Token";
|
| 77 |
return;
|
| 78 |
}
|
| 79 |
|
|
|
|
| 93 |
faceswap: config.faceModel
|
| 94 |
};
|
| 95 |
|
| 96 |
+
outputs[kind].textContent = "Processing...";
|
| 97 |
|
| 98 |
try {
|
| 99 |
if (["chat", "code", "writing"].includes(kind)) {
|
|
|
|
| 101 |
outputs[kind].textContent = answer;
|
| 102 |
} else {
|
| 103 |
const answer = await hfGenericTask(modelByKind[kind], promptByKind[kind], token);
|
| 104 |
+
outputs[kind].textContent = `Task submitted:\n${answer}`;
|
| 105 |
}
|
| 106 |
} catch (error) {
|
| 107 |
outputs[kind].textContent = String(error);
|
|
|
|
| 144 |
btn.addEventListener("click", async () => {
|
| 145 |
const spaceName = document.getElementById("spaceName").value.trim();
|
| 146 |
if (!spaceName) {
|
| 147 |
+
output.textContent = "Please enter Space name";
|
| 148 |
return;
|
| 149 |
}
|
| 150 |
|
| 151 |
const sdk = document.getElementById("spaceSdk")?.value || "static";
|
| 152 |
const privateFlag = document.getElementById("spacePrivate")?.checked ? " --private" : "";
|
| 153 |
|
| 154 |
+
const cmd = `HF_TOKEN=your_token python scripts/deploy_to_hf_space.py --space ${spaceName} --sdk ${sdk}${privateFlag}`;
|
| 155 |
output.textContent = cmd;
|
| 156 |
|
| 157 |
try {
|
| 158 |
await navigator.clipboard.writeText(cmd);
|
| 159 |
+
output.textContent += "\n\n✅ Command copied!";
|
| 160 |
} catch {
|
| 161 |
+
output.textContent += "\n\n⚠️ Failed to copy.";
|
| 162 |
}
|
| 163 |
});
|
| 164 |
}
|