Spaces:
Running
Running
Update index.html
Browse files- index.html +52 -16
index.html
CHANGED
|
@@ -33,9 +33,7 @@
|
|
| 33 |
</div>
|
| 34 |
</div>
|
| 35 |
|
| 36 |
-
<script
|
| 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');
|
|
@@ -52,15 +50,30 @@
|
|
| 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',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
});
|
|
|
|
| 60 |
status.innerText = "SUPREME CORE: ONLINE (PC)";
|
| 61 |
unlock();
|
| 62 |
} catch (err) {
|
| 63 |
-
status.innerText = "SUPREME CORE: ONLINE (
|
| 64 |
unlock();
|
| 65 |
}
|
| 66 |
}
|
|
@@ -80,7 +93,6 @@
|
|
| 80 |
input.value = '';
|
| 81 |
input.disabled = true;
|
| 82 |
btn.disabled = true;
|
| 83 |
-
status.innerText = "STREAMING...";
|
| 84 |
|
| 85 |
const botMsgDiv = document.createElement('div');
|
| 86 |
botMsgDiv.className = 'msg bot';
|
|
@@ -89,30 +101,53 @@
|
|
| 89 |
|
| 90 |
try {
|
| 91 |
if (isMobile || !generator) {
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
//
|
| 95 |
const response = await fetch("https://api-inference.huggingface.co/models/Qwen/Qwen2.5-7B-Instruct", {
|
| 96 |
method: "POST",
|
| 97 |
-
headers: {
|
|
|
|
|
|
|
| 98 |
body: JSON.stringify({
|
| 99 |
-
inputs: val,
|
| 100 |
-
parameters: { max_new_tokens: 500,
|
| 101 |
})
|
| 102 |
});
|
| 103 |
|
| 104 |
if (!response.ok) {
|
| 105 |
-
|
|
|
|
| 106 |
}
|
| 107 |
|
| 108 |
const data = await response.json();
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
} else {
|
|
|
|
|
|
|
| 112 |
const out = await generator([{role: "user", content: val}], { max_new_tokens: 500 });
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
}
|
| 115 |
} catch (err) {
|
|
|
|
| 116 |
botMsgDiv.innerText = `CORE STUTTER: ${err.message}`;
|
| 117 |
}
|
| 118 |
|
|
@@ -132,6 +167,7 @@
|
|
| 132 |
|
| 133 |
btn.onclick = talk;
|
| 134 |
input.onkeypress = (e) => { if (e.key === 'Enter') talk(); };
|
|
|
|
| 135 |
init();
|
| 136 |
</script>
|
| 137 |
</body>
|
|
|
|
| 33 |
</div>
|
| 34 |
</div>
|
| 35 |
|
| 36 |
+
<script>
|
|
|
|
|
|
|
| 37 |
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
| 38 |
|
| 39 |
const status = document.getElementById('status');
|
|
|
|
| 50 |
unlock();
|
| 51 |
} else {
|
| 52 |
status.innerText = "LINKING PC NEURAL CORE...";
|
| 53 |
+
prog.style.display = 'block'; // Make progress bar visible
|
| 54 |
try {
|
| 55 |
+
const { pipeline, env } = await import('https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0');
|
| 56 |
env.allowLocalModels = false;
|
| 57 |
+
|
| 58 |
+
// Added progress callback so PC doesn't look frozen during download
|
| 59 |
generator = await pipeline('text-generation', 'onnx-community/Qwen2.5-0.5B-Instruct', {
|
| 60 |
+
dtype: 'q4',
|
| 61 |
+
device: 'webgpu',
|
| 62 |
+
progress_callback: (data) => {
|
| 63 |
+
if (data.status === 'progress') {
|
| 64 |
+
prog.value = data.progress;
|
| 65 |
+
status.innerText = `DOWNLOADING NEURAL WEIGHTS: ${Math.round(data.progress)}%`;
|
| 66 |
+
} else if (data.status === 'ready') {
|
| 67 |
+
status.innerText = "SUPREME CORE: ONLINE (PC)";
|
| 68 |
+
unlock();
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
});
|
| 72 |
+
|
| 73 |
status.innerText = "SUPREME CORE: ONLINE (PC)";
|
| 74 |
unlock();
|
| 75 |
} catch (err) {
|
| 76 |
+
status.innerText = "SUPREME CORE: ONLINE (CLOUD FALLBACK)";
|
| 77 |
unlock();
|
| 78 |
}
|
| 79 |
}
|
|
|
|
| 93 |
input.value = '';
|
| 94 |
input.disabled = true;
|
| 95 |
btn.disabled = true;
|
|
|
|
| 96 |
|
| 97 |
const botMsgDiv = document.createElement('div');
|
| 98 |
botMsgDiv.className = 'msg bot';
|
|
|
|
| 101 |
|
| 102 |
try {
|
| 103 |
if (isMobile || !generator) {
|
| 104 |
+
status.innerText = "STREAMING FROM CLOUD...";
|
| 105 |
+
|
| 106 |
+
// Zero Token Method (No auth header, standard fetch to bypass mobile Safari dropping streams)
|
| 107 |
const response = await fetch("https://api-inference.huggingface.co/models/Qwen/Qwen2.5-7B-Instruct", {
|
| 108 |
method: "POST",
|
| 109 |
+
headers: {
|
| 110 |
+
"Content-Type": "application/json"
|
| 111 |
+
},
|
| 112 |
body: JSON.stringify({
|
| 113 |
+
inputs: "<|im_start|>user\n" + val + "<|im_end|>\n<|im_start|>assistant\n",
|
| 114 |
+
parameters: { max_new_tokens: 500, return_full_text: false }
|
| 115 |
})
|
| 116 |
});
|
| 117 |
|
| 118 |
if (!response.ok) {
|
| 119 |
+
const errText = await response.text();
|
| 120 |
+
throw new Error(`HTTP ${response.status} - Open Interface Blocked.`);
|
| 121 |
}
|
| 122 |
|
| 123 |
const data = await response.json();
|
| 124 |
+
let reply = "";
|
| 125 |
+
if (Array.isArray(data) && data[0].generated_text) {
|
| 126 |
+
reply = data[0].generated_text;
|
| 127 |
+
} else if (data.generated_text) {
|
| 128 |
+
reply = data.generated_text;
|
| 129 |
+
} else {
|
| 130 |
+
reply = "LINK STABLE - NO DATA RECEIVED.";
|
| 131 |
+
}
|
| 132 |
+
botMsgDiv.innerText = reply.trim();
|
| 133 |
+
|
| 134 |
} else {
|
| 135 |
+
// Update status so you know PC isn't frozen while it thinks
|
| 136 |
+
status.innerText = "GENERATING LOCALLY (MAY TAKE A MOMENT)...";
|
| 137 |
const out = await generator([{role: "user", content: val}], { max_new_tokens: 500 });
|
| 138 |
+
|
| 139 |
+
// Properly parse the V3 Transformers format
|
| 140 |
+
if (Array.isArray(out) && Array.isArray(out[0].generated_text)) {
|
| 141 |
+
const msgs = out[0].generated_text;
|
| 142 |
+
botMsgDiv.innerText = msgs[msgs.length - 1].content;
|
| 143 |
+
} else if (Array.isArray(out) && out[0].generated_text) {
|
| 144 |
+
botMsgDiv.innerText = out[0].generated_text;
|
| 145 |
+
} else {
|
| 146 |
+
botMsgDiv.innerText = "CORE SYNTAX ERROR.";
|
| 147 |
+
}
|
| 148 |
}
|
| 149 |
} catch (err) {
|
| 150 |
+
console.error("Transmission Error:", err);
|
| 151 |
botMsgDiv.innerText = `CORE STUTTER: ${err.message}`;
|
| 152 |
}
|
| 153 |
|
|
|
|
| 167 |
|
| 168 |
btn.onclick = talk;
|
| 169 |
input.onkeypress = (e) => { if (e.key === 'Enter') talk(); };
|
| 170 |
+
|
| 171 |
init();
|
| 172 |
</script>
|
| 173 |
</body>
|