FlashCode-Lab commited on
Commit
8345033
·
verified ·
1 Parent(s): 24f475b

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +10 -12
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
- // 修复点 1: 全角冒号改为半角
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
- // 修复点 2: 全角冒号改为半角,并将单引号改为反引号以支持变量
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 = "请先填写 Hugging Face Token";
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 = `已提交任务(原始响应):\n${answer}`;
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 = "请先填写 Space 名称";
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=你的hf_token python scripts/deploy_to_hf_space.py --space ${spaceName} --sdk ${sdk}${privateFlag}`;
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
  }