Spaces:
Running
Running
Update index.html
Browse files- index.html +17 -49
index.html
CHANGED
|
@@ -34,14 +34,10 @@
|
|
| 34 |
</div>
|
| 35 |
|
| 36 |
<script type="module">
|
| 37 |
-
// Using Module type for the transformer imports
|
| 38 |
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0';
|
| 39 |
|
| 40 |
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
| 41 |
|
| 42 |
-
// IMPORTANT: Replace this with a FRESH token if the old one was sniped by GitHub.
|
| 43 |
-
const HF_TOKEN = "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";
|
| 44 |
-
|
| 45 |
const status = document.getElementById('status');
|
| 46 |
const chat = document.getElementById('chat');
|
| 47 |
const input = document.getElementById('user-input');
|
|
@@ -52,20 +48,19 @@
|
|
| 52 |
|
| 53 |
async function init() {
|
| 54 |
if (isMobile) {
|
| 55 |
-
status.innerText = "SUPREME CORE: ONLINE (MOBILE
|
| 56 |
unlock();
|
| 57 |
} else {
|
| 58 |
-
status.innerText = "LINKING PC NEURAL CORE
|
| 59 |
try {
|
| 60 |
env.allowLocalModels = false;
|
| 61 |
generator = await pipeline('text-generation', 'onnx-community/Qwen2.5-0.5B-Instruct', {
|
| 62 |
dtype: 'q4', device: 'webgpu'
|
| 63 |
});
|
| 64 |
-
status.innerText = "SUPREME CORE: ONLINE (
|
| 65 |
unlock();
|
| 66 |
} catch (err) {
|
| 67 |
-
|
| 68 |
-
status.innerText = "SUPREME CORE: ONLINE (CLOUD FALLBACK)";
|
| 69 |
unlock();
|
| 70 |
}
|
| 71 |
}
|
|
@@ -94,51 +89,26 @@
|
|
| 94 |
|
| 95 |
try {
|
| 96 |
if (isMobile || !generator) {
|
| 97 |
-
//
|
| 98 |
-
|
|
|
|
|
|
|
| 99 |
method: "POST",
|
| 100 |
-
headers: {
|
| 101 |
-
"Authorization": `Bearer ${HF_TOKEN}`,
|
| 102 |
-
"Content-Type": "application/json"
|
| 103 |
-
},
|
| 104 |
body: JSON.stringify({
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
max_tokens: 500,
|
| 108 |
-
stream: true
|
| 109 |
})
|
| 110 |
});
|
| 111 |
|
| 112 |
-
if (!response.ok)
|
| 113 |
-
|
| 114 |
-
const reader = response.body.getReader();
|
| 115 |
-
const decoder = new TextDecoder();
|
| 116 |
-
let fullText = "";
|
| 117 |
-
|
| 118 |
-
while (true) {
|
| 119 |
-
const { done, value } = await reader.read();
|
| 120 |
-
if (done) break;
|
| 121 |
-
|
| 122 |
-
const chunk = decoder.decode(value, { stream: true });
|
| 123 |
-
const lines = chunk.split('\n');
|
| 124 |
-
|
| 125 |
-
for (const line of lines) {
|
| 126 |
-
if (line.startsWith('data: ')) {
|
| 127 |
-
if (line.includes('[DONE]')) break;
|
| 128 |
-
try {
|
| 129 |
-
const json = JSON.parse(line.substring(6));
|
| 130 |
-
const content = json.choices[0].delta.content;
|
| 131 |
-
if (content) {
|
| 132 |
-
fullText += content;
|
| 133 |
-
botMsgDiv.innerText = fullText;
|
| 134 |
-
chat.scrollTop = chat.scrollHeight;
|
| 135 |
-
}
|
| 136 |
-
} catch (e) {}
|
| 137 |
-
}
|
| 138 |
-
}
|
| 139 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
} else {
|
| 141 |
-
// PC Path: Local Generation
|
| 142 |
const out = await generator([{role: "user", content: val}], { max_new_tokens: 500 });
|
| 143 |
botMsgDiv.innerText = out[0].generated_text[out[0].generated_text.length - 1].content;
|
| 144 |
}
|
|
@@ -150,7 +120,6 @@
|
|
| 150 |
input.disabled = false;
|
| 151 |
btn.disabled = false;
|
| 152 |
chat.scrollTop = chat.scrollHeight;
|
| 153 |
-
input.focus();
|
| 154 |
}
|
| 155 |
|
| 156 |
function addMsg(text, type) {
|
|
@@ -163,7 +132,6 @@
|
|
| 163 |
|
| 164 |
btn.onclick = talk;
|
| 165 |
input.onkeypress = (e) => { if (e.key === 'Enter') talk(); };
|
| 166 |
-
|
| 167 |
init();
|
| 168 |
</script>
|
| 169 |
</body>
|
|
|
|
| 34 |
</div>
|
| 35 |
|
| 36 |
<script type="module">
|
|
|
|
| 37 |
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0';
|
| 38 |
|
| 39 |
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
| 40 |
|
|
|
|
|
|
|
|
|
|
| 41 |
const status = document.getElementById('status');
|
| 42 |
const chat = document.getElementById('chat');
|
| 43 |
const input = document.getElementById('user-input');
|
|
|
|
| 48 |
|
| 49 |
async function init() {
|
| 50 |
if (isMobile) {
|
| 51 |
+
status.innerText = "SUPREME CORE: ONLINE (MOBILE)";
|
| 52 |
unlock();
|
| 53 |
} else {
|
| 54 |
+
status.innerText = "LINKING PC NEURAL CORE...";
|
| 55 |
try {
|
| 56 |
env.allowLocalModels = false;
|
| 57 |
generator = await pipeline('text-generation', 'onnx-community/Qwen2.5-0.5B-Instruct', {
|
| 58 |
dtype: 'q4', device: 'webgpu'
|
| 59 |
});
|
| 60 |
+
status.innerText = "SUPREME CORE: ONLINE (PC)";
|
| 61 |
unlock();
|
| 62 |
} catch (err) {
|
| 63 |
+
status.innerText = "SUPREME CORE: ONLINE (MOBILE BRIDGE)";
|
|
|
|
| 64 |
unlock();
|
| 65 |
}
|
| 66 |
}
|
|
|
|
| 89 |
|
| 90 |
try {
|
| 91 |
if (isMobile || !generator) {
|
| 92 |
+
// ZERO-TOKEN STRATEGY
|
| 93 |
+
// Points to the public Inference API. When hosted on HF Spaces,
|
| 94 |
+
// some models allow connection without a token if origin is verified.
|
| 95 |
+
const response = await fetch("https://api-inference.huggingface.co/models/Qwen/Qwen2.5-7B-Instruct", {
|
| 96 |
method: "POST",
|
| 97 |
+
headers: { "Content-Type": "application/json" },
|
|
|
|
|
|
|
|
|
|
| 98 |
body: JSON.stringify({
|
| 99 |
+
inputs: val,
|
| 100 |
+
parameters: { max_new_tokens: 500, wait_for_model: true }
|
|
|
|
|
|
|
| 101 |
})
|
| 102 |
});
|
| 103 |
|
| 104 |
+
if (!response.ok) {
|
| 105 |
+
throw new Error("SECURE LINK REQUIRED. Use the 'Split Token' method if this fails.");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
}
|
| 107 |
+
|
| 108 |
+
const data = await response.json();
|
| 109 |
+
const reply = data[0]?.generated_text || "LINK STABLE - NO DATA.";
|
| 110 |
+
botMsgDiv.innerText = reply;
|
| 111 |
} else {
|
|
|
|
| 112 |
const out = await generator([{role: "user", content: val}], { max_new_tokens: 500 });
|
| 113 |
botMsgDiv.innerText = out[0].generated_text[out[0].generated_text.length - 1].content;
|
| 114 |
}
|
|
|
|
| 120 |
input.disabled = false;
|
| 121 |
btn.disabled = false;
|
| 122 |
chat.scrollTop = chat.scrollHeight;
|
|
|
|
| 123 |
}
|
| 124 |
|
| 125 |
function addMsg(text, type) {
|
|
|
|
| 132 |
|
| 133 |
btn.onclick = talk;
|
| 134 |
input.onkeypress = (e) => { if (e.key === 'Enter') talk(); };
|
|
|
|
| 135 |
init();
|
| 136 |
</script>
|
| 137 |
</body>
|