Here is the updated technical specification, incorporating the dynamic palette configuration.
602a007 verified Download script.js from CryptoCaverns-AL/visual-neural-network-editor: direct link, hf CLI and curl.
- Browser
- Download file 4.92 kB
-
https://huggingface.co/spaces/CryptoCaverns-AL/visual-neural-network-editor/resolve/main/script.js
- Command line
-
hf download hf://spaces/CryptoCaverns-AL/visual-neural-network-editor/script.js
-
curl -L -o script.js https://huggingface.co/spaces/CryptoCaverns-AL/visual-neural-network-editor/resolve/main/script.js
4.92 kB
| // Global state management | |
| let globalState = { | |
| network: { | |
| id: "network_1", | |
| properties: {}, | |
| layers: [ | |
| { | |
| id: "layer_1", | |
| type: "Input", | |
| properties: {}, | |
| neurons: [ | |
| { | |
| id: "neuron_1a", | |
| type: "InputNeuron", | |
| properties: { | |
| bias: 0.1, | |
| activationFunction: "relu" | |
| } | |
| }, | |
| { | |
| id: "neuron_1b", | |
| type: "InputNeuron", | |
| properties: { | |
| bias: 0.2, | |
| activationFunction: "sigmoid" | |
| } | |
| } | |
| ] | |
| }, | |
| { | |
| id: "layer_2", | |
| type: "Hidden", | |
| properties: {}, | |
| neurons: [ | |
| { | |
| id: "neuron_2a", | |
| type: "HiddenNeuron", | |
| properties: { | |
| bias: 0.05, | |
| activationFunction: "tanh" | |
| } | |
| } | |
| ] | |
| }, | |
| { | |
| id: "layer_3", | |
| type: "Output", | |
| properties: {}, | |
| neurons: [ | |
| { | |
| id: "neuron_3a", | |
| type: "OutputNeuron", | |
| properties: { | |
| bias: -0.1, | |
| activationFunction: "softmax" | |
| } | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| }; | |
| // Initialize Konva stage | |
| document.addEventListener('DOMContentLoaded', function() { | |
| const width = document.getElementById('konva-stage').offsetWidth; | |
| const height = document.getElementById('konva-stage').offsetHeight; | |
| const stage = new Konva.Stage({ | |
| container: 'konva-stage', | |
| width: width, | |
| height: height, | |
| draggable: true | |
| }); | |
| const layer = new Konva.Layer(); | |
| // Add some sample shapes to represent neural network components | |
| const inputLayer = new Konva.Rect({ | |
| x: 100, | |
| y: 100, | |
| width: 150, | |
| height: 80, | |
| fill: '#0ea5e9', | |
| stroke: '#0284c7', | |
| strokeWidth: 2, | |
| cornerRadius: 5 | |
| }); | |
| const hiddenLayer = new Konva.Rect({ | |
| x: 300, | |
| y: 100, | |
| width: 150, | |
| height: 80, | |
| fill: '#8b5cf6', | |
| stroke: '#7c3aed', | |
| strokeWidth: 2, | |
| cornerRadius: 5 | |
| }); | |
| const outputLayer = new Konva.Rect({ | |
| x: 500, | |
| y: 100, | |
| width: 150, | |
| height: 80, | |
| fill: '#ec4899', | |
| stroke: '#db2777', | |
| strokeWidth: 2, | |
| cornerRadius: 5 | |
| }); | |
| // Add neurons | |
| const neuron1 = new Konva.Circle({ | |
| x: 175, | |
| y: 120, | |
| radius: 15, | |
| fill: '#0284c7', | |
| stroke: '#0369a1', | |
| strokeWidth: 1 | |
| }); | |
| const neuron2 = new Konva.Circle({ | |
| x: 175, | |
| y: 160, | |
| radius: 15, | |
| fill: '#0284c7', | |
| stroke: '#0369a1', | |
| strokeWidth: 1 | |
| }); | |
| const neuron3 = new Konva.Circle({ | |
| x: 375, | |
| y: 140, | |
| radius: 15, | |
| fill: '#6d28d9', | |
| stroke: '#5b21b6', | |
| strokeWidth: 1 | |
| }); | |
| const neuron4 = new Konva.Circle({ | |
| x: 575, | |
| y: 140, | |
| radius: 15, | |
| fill: '#be185d', | |
| stroke: '#9d174d', | |
| strokeWidth: 1 | |
| }); | |
| // Add connections | |
| const connection1 = new Konva.Line({ | |
| points: [190, 120, 360, 135], | |
| stroke: '#94a3b8', | |
| strokeWidth: 2, | |
| tension: 0 | |
| }); | |
| const connection2 = new Konva.Line({ | |
| points: [190, 160, 360, 145], | |
| stroke: '#94a3b8', | |
| strokeWidth: 2, | |
| tension: 0 | |
| }); | |
| const connection3 = new Konva.Line({ | |
| points: [390, 140, 560, 140], | |
| stroke: '#94a3b8', | |
| strokeWidth: 2, | |
| tension: 0 | |
| }); | |
| // Add labels | |
| const inputLabel = new Konva.Text({ | |
| x: 110, | |
| y: 110, | |
| text: 'Input Layer', | |
| fontSize: 14, | |
| fill: 'white' | |
| }); | |
| const hiddenLabel = new Konva.Text({ | |
| x: 310, | |
| y: 110, | |
| text: 'Hidden Layer', | |
| fontSize: 14, | |
| fill: 'white' | |
| }); | |
| const outputLabel = new Konva.Text({ | |
| x: 510, | |
| y: 110, | |
| text: 'Output Layer', | |
| fontSize: 14, | |
| fill: 'white' | |
| }); | |
| // Add all elements to layer | |
| layer.add(connection1); | |
| layer.add(connection2); | |
| layer.add(connection3); | |
| layer.add(inputLayer); | |
| layer.add(hiddenLayer); | |
| layer.add(outputLayer); | |
| layer.add(neuron1); | |
| layer.add(neuron2); | |
| layer.add(neuron3); | |
| layer.add(neuron4); | |
| layer.add(inputLabel); | |
| layer.add(hiddenLabel); | |
| layer.add(outputLabel); | |
| // Add layer to stage | |
| stage.add(layer); | |
| // Zoom functionality | |
| stage.on('wheel', (e) => { | |
| e.evt.preventDefault(); | |
| const oldScale = stage.scaleX(); | |
| const pointer = stage.getPointerPosition(); | |
| const mousePointTo = { | |
| x: (pointer.x - stage.x()) / oldScale, | |
| y: (pointer.y - stage.y()) / oldScale, | |
| }; | |
| const newScale = e.evt.deltaY > 0 ? oldScale * 0.9 : oldScale * 1.1; | |
| stage.scale({ x: newScale, y: newScale }); | |
| const newPos = { | |
| x: pointer.x - mousePointTo.x * newScale, | |
| y: pointer.y - mousePointTo.y * newScale, | |
| }; | |
| stage.position(newPos); | |
| }); | |
| // Console functionality | |
| const consoleInput = document.querySelector('#console-output + div input'); | |
| const consoleOutput = document.getElementById('console-output'); |