Update index.js
Browse files
index.js
CHANGED
|
@@ -1,22 +1,53 @@
|
|
| 1 |
// index.js
|
| 2 |
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers';
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
const analyzeForm = document.getElementById('analyze-form');
|
|
|
|
| 5 |
const inputText = document.getElementById('inputText');
|
| 6 |
const resultSection = document.getElementById('result');
|
| 7 |
const analyzeButton = document.getElementById('analyzeButton');
|
| 8 |
-
|
| 9 |
let sentimentPipeline;
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
analyzeButton.disabled = true;
|
| 13 |
analyzeButton.textContent = 'Loading model...';
|
| 14 |
-
sentimentPipeline = await pipeline('sentiment-analysis');
|
| 15 |
analyzeButton.textContent = 'Analyze Sentiment';
|
| 16 |
analyzeButton.disabled = false;
|
| 17 |
}
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
event.preventDefault();
|
| 21 |
const text = inputText.value.trim();
|
| 22 |
if (!text) return;
|
|
@@ -29,10 +60,10 @@ analyzeForm.addEventListener('submit', async (event) => {
|
|
| 29 |
const output = await sentimentPipeline(text);
|
| 30 |
const { label, score } = output[0];
|
| 31 |
resultSection.textContent = `Sentiment: ${label} (Confidence: ${(score * 100).toFixed(2)}%)`;
|
| 32 |
-
} catch (
|
| 33 |
resultSection.textContent = 'Error analyzing sentiment.';
|
| 34 |
}
|
| 35 |
|
| 36 |
analyzeButton.textContent = 'Analyze Sentiment';
|
| 37 |
analyzeButton.disabled = false;
|
| 38 |
-
});
|
|
|
|
| 1 |
// index.js
|
| 2 |
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers';
|
| 3 |
|
| 4 |
+
// Define available models (mirror of constants.py AVAILABLE_MODELS)
|
| 5 |
+
const AVAILABLE_MODELS = [
|
| 6 |
+
{ name: "Moonshot Kimi-K2", id: "moonshotai/Kimi-K2-Instruct" },
|
| 7 |
+
{ name: "DeepSeek V3", id: "deepseek-ai/DeepSeek-V3-0324" },
|
| 8 |
+
{ name: "DeepSeek R1", id: "deepseek-ai/DeepSeek-R1-0528" },
|
| 9 |
+
{ name: "ERNIE-4.5-VL", id: "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT" },
|
| 10 |
+
{ name: "MiniMax M1", id: "MiniMaxAI/MiniMax-M1-80k" },
|
| 11 |
+
{ name: "Qwen3-235B-A22B", id: "Qwen/Qwen3-235B-A22B" },
|
| 12 |
+
{ name: "SmolLM3-3B", id: "HuggingFaceTB/SmolLM3-3B" },
|
| 13 |
+
{ name: "GLM-4.1V-9B-Thinking", id: "THUDM/GLM-4.1V-9B-Thinking" },
|
| 14 |
+
{ name: "Qwen3-235B-A22B-Instruct-2507", id: "Qwen/Qwen3-235B-A22B-Instruct-2507" },
|
| 15 |
+
{ name: "Qwen3-Coder-480B-A35B", id: "Qwen/Qwen3-Coder-480B-A35B-Instruct" }
|
| 16 |
+
];
|
| 17 |
+
|
| 18 |
const analyzeForm = document.getElementById('analyze-form');
|
| 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 model dropdown
|
| 26 |
+
AVAILABLE_MODELS.forEach(model => {
|
| 27 |
+
const opt = document.createElement('option');
|
| 28 |
+
opt.value = model.id;
|
| 29 |
+
opt.textContent = model.name;
|
| 30 |
+
modelSelect.appendChild(opt);
|
| 31 |
+
});
|
| 32 |
+
|
| 33 |
+
async function initPipeline(modelId) {
|
| 34 |
analyzeButton.disabled = true;
|
| 35 |
analyzeButton.textContent = 'Loading model...';
|
| 36 |
+
sentimentPipeline = await pipeline('sentiment-analysis', modelId);
|
| 37 |
analyzeButton.textContent = 'Analyze Sentiment';
|
| 38 |
analyzeButton.disabled = false;
|
| 39 |
}
|
| 40 |
|
| 41 |
+
// Initialize with first model
|
| 42 |
+
initPipeline(modelSelect.value);
|
| 43 |
+
|
| 44 |
+
// Re-init pipeline on model change
|
| 45 |
+
modelSelect.addEventListener('change', () => {
|
| 46 |
+
initPipeline(modelSelect.value);
|
| 47 |
+
resultSection.textContent = '';
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
analyzeForm.addEventListener('submit', async event => {
|
| 51 |
event.preventDefault();
|
| 52 |
const text = inputText.value.trim();
|
| 53 |
if (!text) return;
|
|
|
|
| 60 |
const output = await sentimentPipeline(text);
|
| 61 |
const { label, score } = output[0];
|
| 62 |
resultSection.textContent = `Sentiment: ${label} (Confidence: ${(score * 100).toFixed(2)}%)`;
|
| 63 |
+
} catch (err) {
|
| 64 |
resultSection.textContent = 'Error analyzing sentiment.';
|
| 65 |
}
|
| 66 |
|
| 67 |
analyzeButton.textContent = 'Analyze Sentiment';
|
| 68 |
analyzeButton.disabled = false;
|
| 69 |
+
});
|