Update index.js
Browse files
index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
|
|
|
|
|
| 1 |
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers';
|
| 2 |
|
| 3 |
-
// Front-end copy of the
|
| 4 |
const AVAILABLE_MODELS = [
|
| 5 |
{ name: "Moonshot Kimi-K2", id: "moonshotai/Kimi-K2-Instruct" },
|
| 6 |
{ name: "DeepSeek V3", id: "deepseek-ai/DeepSeek-V3-0324" },
|
|
@@ -8,78 +10,68 @@ const AVAILABLE_MODELS = [
|
|
| 8 |
{ name: "ERNIE-4.5-VL", id: "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT" },
|
| 9 |
{ name: "MiniMax M1", id: "MiniMaxAI/MiniMax-M1-80k" },
|
| 10 |
{ name: "Qwen3-235B-A22B", id: "Qwen/Qwen3-235B-A22B" },
|
|
|
|
| 11 |
{ name: "SmolLM3-3B", id: "HuggingFaceTB/SmolLM3-3B" },
|
| 12 |
{ name: "GLM-4.1V-9B-Thinking", id: "THUDM/GLM-4.1V-9B-Thinking" },
|
|
|
|
|
|
|
| 13 |
{ name: "Qwen3-235B-A22B-Instruct-2507", id: "Qwen/Qwen3-235B-A22B-Instruct-2507" },
|
| 14 |
-
{ name: "Qwen3-Coder-480B-A35B", id: "Qwen/Qwen3-Coder-480B-A35B-Instruct" }
|
| 15 |
-
{ name: "OpenAI GPT-4", id: "openai/gpt-4" },
|
| 16 |
-
{ name: "Gemini Pro", id: "gemini/pro" },
|
| 17 |
-
{ name: "Fireworks AI", id: "fireworks-ai/fireworks-v1" }
|
| 18 |
];
|
| 19 |
|
| 20 |
-
// DOM Elements
|
| 21 |
const modelSelect = document.getElementById('modelSelect');
|
| 22 |
-
const
|
| 23 |
-
const
|
| 24 |
-
const
|
|
|
|
| 25 |
|
| 26 |
-
let
|
| 27 |
|
| 28 |
-
// Populate model dropdown
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
});
|
| 36 |
-
}
|
| 37 |
|
| 38 |
-
// Initialize pipeline for
|
| 39 |
async function initPipeline(modelId) {
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
}
|
| 46 |
|
| 47 |
-
//
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
|
| 56 |
try {
|
| 57 |
-
const
|
| 58 |
-
const
|
| 59 |
-
|
| 60 |
-
: outputs.generated_text;
|
| 61 |
-
codeOutput.textContent = generated;
|
| 62 |
} catch (err) {
|
| 63 |
console.error(err);
|
| 64 |
-
|
| 65 |
}
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
// Event bindings
|
| 72 |
-
window.addEventListener('DOMContentLoaded', async () => {
|
| 73 |
-
populateModels();
|
| 74 |
-
await initPipeline(modelSelect.value);
|
| 75 |
-
});
|
| 76 |
-
|
| 77 |
-
modelSelect.addEventListener('change', () => {
|
| 78 |
-
codeOutput.textContent = '';
|
| 79 |
-
initPipeline(modelSelect.value);
|
| 80 |
});
|
| 81 |
-
|
| 82 |
-
generateBtn.addEventListener('click', handleGenerate);
|
| 83 |
-
|
| 84 |
-
// Expose functions (for debugging)
|
| 85 |
-
window._codeApp = { initPipeline, handleGenerate };
|
|
|
|
| 1 |
+
// index.js
|
| 2 |
+
|
| 3 |
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers';
|
| 4 |
|
| 5 |
+
// Front-end copy of the Python AVAILABLE_MODELS list for dropdown population:
|
| 6 |
const AVAILABLE_MODELS = [
|
| 7 |
{ name: "Moonshot Kimi-K2", id: "moonshotai/Kimi-K2-Instruct" },
|
| 8 |
{ name: "DeepSeek V3", id: "deepseek-ai/DeepSeek-V3-0324" },
|
|
|
|
| 10 |
{ name: "ERNIE-4.5-VL", id: "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT" },
|
| 11 |
{ name: "MiniMax M1", id: "MiniMaxAI/MiniMax-M1-80k" },
|
| 12 |
{ name: "Qwen3-235B-A22B", id: "Qwen/Qwen3-235B-A22B" },
|
| 13 |
+
{ name: "Qwen3-32B", id: "Qwen/Qwen3-32B" }, // newly added
|
| 14 |
{ name: "SmolLM3-3B", id: "HuggingFaceTB/SmolLM3-3B" },
|
| 15 |
{ name: "GLM-4.1V-9B-Thinking", id: "THUDM/GLM-4.1V-9B-Thinking" },
|
| 16 |
+
{ name: "LLaMA-2-70B-Chat", id: "meta-llama/Llama-2-70b-chat" }, // powerful addition
|
| 17 |
+
{ name: "Mistral-7B-Instruct", id: "mistralai/Mistral-7B-Instruct" }, // powerful addition
|
| 18 |
{ name: "Qwen3-235B-A22B-Instruct-2507", id: "Qwen/Qwen3-235B-A22B-Instruct-2507" },
|
| 19 |
+
{ name: "Qwen3-Coder-480B-A35B", id: "Qwen/Qwen3-Coder-480B-A35B-Instruct" }
|
|
|
|
|
|
|
|
|
|
| 20 |
];
|
| 21 |
|
|
|
|
| 22 |
const modelSelect = document.getElementById('modelSelect');
|
| 23 |
+
const analyzeForm = document.getElementById('analyze-form');
|
| 24 |
+
const inputText = document.getElementById('inputText');
|
| 25 |
+
const analyzeButton = document.getElementById('analyzeButton');
|
| 26 |
+
const resultSection = document.getElementById('result');
|
| 27 |
|
| 28 |
+
let sentimentPipeline = null;
|
| 29 |
|
| 30 |
+
// Populate the model dropdown
|
| 31 |
+
AVAILABLE_MODELS.forEach(model => {
|
| 32 |
+
const option = document.createElement('option');
|
| 33 |
+
option.value = model.id;
|
| 34 |
+
option.textContent = model.name;
|
| 35 |
+
modelSelect.appendChild(option);
|
| 36 |
+
});
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
// Initialize pipeline for the selected model
|
| 39 |
async function initPipeline(modelId) {
|
| 40 |
+
analyzeButton.disabled = true;
|
| 41 |
+
analyzeButton.textContent = 'Loading model…';
|
| 42 |
+
sentimentPipeline = await pipeline('sentiment-analysis', modelId);
|
| 43 |
+
analyzeButton.textContent = 'Analyze Sentiment';
|
| 44 |
+
analyzeButton.disabled = false;
|
| 45 |
}
|
| 46 |
|
| 47 |
+
// On page load: initialize with the first model
|
| 48 |
+
initPipeline(modelSelect.value);
|
| 49 |
+
|
| 50 |
+
// When user changes model: reinitialize pipeline
|
| 51 |
+
modelSelect.addEventListener('change', () => {
|
| 52 |
+
resultSection.textContent = '';
|
| 53 |
+
initPipeline(modelSelect.value);
|
| 54 |
+
});
|
| 55 |
+
|
| 56 |
+
// Handle form submission
|
| 57 |
+
analyzeForm.addEventListener('submit', async (event) => {
|
| 58 |
+
event.preventDefault();
|
| 59 |
+
const text = inputText.value.trim();
|
| 60 |
+
if (!text) return;
|
| 61 |
|
| 62 |
+
analyzeButton.disabled = true;
|
| 63 |
+
analyzeButton.textContent = 'Analyzing…';
|
| 64 |
+
resultSection.textContent = '';
|
| 65 |
|
| 66 |
try {
|
| 67 |
+
const [output] = await sentimentPipeline(text);
|
| 68 |
+
const { label, score } = output;
|
| 69 |
+
resultSection.textContent = `Sentiment: ${label} (Confidence: ${(score * 100).toFixed(2)}%)`;
|
|
|
|
|
|
|
| 70 |
} catch (err) {
|
| 71 |
console.error(err);
|
| 72 |
+
resultSection.textContent = 'Error analyzing sentiment.';
|
| 73 |
}
|
| 74 |
|
| 75 |
+
analyzeButton.textContent = 'Analyze Sentiment';
|
| 76 |
+
analyzeButton.disabled = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|