Update index.js
Browse files
index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
| 4 |
const AVAILABLE_MODELS = [
|
| 5 |
{ name: "Moonshot Kimi-K2", id: "moonshotai/Kimi-K2-Instruct" },
|
| 6 |
{ name: "DeepSeek V3", id: "deepseek-ai/DeepSeek-V3-0324" },
|
|
@@ -14,15 +16,13 @@ const AVAILABLE_MODELS = [
|
|
| 14 |
{ name: "Qwen3-Coder-480B-A35B", id: "Qwen/Qwen3-Coder-480B-A35B-Instruct" }
|
| 15 |
];
|
| 16 |
|
| 17 |
-
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers';
|
| 18 |
-
|
| 19 |
const modelSelect = document.getElementById('modelSelect');
|
| 20 |
const inputText = document.getElementById('inputText');
|
| 21 |
const resultSection = document.getElementById('result');
|
| 22 |
const analyzeButton = document.getElementById('analyzeButton');
|
| 23 |
let sentimentPipeline;
|
| 24 |
|
| 25 |
-
// Populate
|
| 26 |
AVAILABLE_MODELS.forEach(model => {
|
| 27 |
const opt = document.createElement('option');
|
| 28 |
opt.value = model.id;
|
|
@@ -38,16 +38,16 @@ async function initPipeline(modelId) {
|
|
| 38 |
analyzeButton.disabled = false;
|
| 39 |
}
|
| 40 |
|
| 41 |
-
// Initialize
|
| 42 |
initPipeline(modelSelect.value);
|
| 43 |
|
| 44 |
-
// Re-
|
| 45 |
modelSelect.addEventListener('change', () => {
|
| 46 |
initPipeline(modelSelect.value);
|
| 47 |
resultSection.textContent = '';
|
| 48 |
});
|
| 49 |
|
| 50 |
-
// Handle form
|
| 51 |
document.getElementById('analyze-form').addEventListener('submit', async event => {
|
| 52 |
event.preventDefault();
|
| 53 |
const text = inputText.value.trim();
|
|
|
|
| 1 |
+
--- index.js ---
|
| 2 |
+
```javascript
|
| 3 |
+
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers';
|
| 4 |
+
|
| 5 |
+
// Frontend copy of AVAILABLE_MODELS from constants.py
|
| 6 |
const AVAILABLE_MODELS = [
|
| 7 |
{ name: "Moonshot Kimi-K2", id: "moonshotai/Kimi-K2-Instruct" },
|
| 8 |
{ name: "DeepSeek V3", id: "deepseek-ai/DeepSeek-V3-0324" },
|
|
|
|
| 16 |
{ name: "Qwen3-Coder-480B-A35B", id: "Qwen/Qwen3-Coder-480B-A35B-Instruct" }
|
| 17 |
];
|
| 18 |
|
|
|
|
|
|
|
| 19 |
const modelSelect = document.getElementById('modelSelect');
|
| 20 |
const inputText = document.getElementById('inputText');
|
| 21 |
const resultSection = document.getElementById('result');
|
| 22 |
const analyzeButton = document.getElementById('analyzeButton');
|
| 23 |
let sentimentPipeline;
|
| 24 |
|
| 25 |
+
// Populate dropdown
|
| 26 |
AVAILABLE_MODELS.forEach(model => {
|
| 27 |
const opt = document.createElement('option');
|
| 28 |
opt.value = model.id;
|
|
|
|
| 38 |
analyzeButton.disabled = false;
|
| 39 |
}
|
| 40 |
|
| 41 |
+
// Initialize with first model
|
| 42 |
initPipeline(modelSelect.value);
|
| 43 |
|
| 44 |
+
// Re-init on change
|
| 45 |
modelSelect.addEventListener('change', () => {
|
| 46 |
initPipeline(modelSelect.value);
|
| 47 |
resultSection.textContent = '';
|
| 48 |
});
|
| 49 |
|
| 50 |
+
// Handle form submission
|
| 51 |
document.getElementById('analyze-form').addEventListener('submit', async event => {
|
| 52 |
event.preventDefault();
|
| 53 |
const text = inputText.value.trim();
|