This code does not work. Can you fix it?

<!DOCTYPE html>
<html>

<head>
    <title>Logistic Regression Predictor</title>
    <!-- Load TensorFlow.js and Google Charts -->
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <style>
        .container {
            margin: 20px;
            font-family: Arial, sans-serif;
        }

        .progress {
            width: 100%;
            height: 20px;
            background-color: #f0f0f0;
        }

        .progress-bar {
            width: 0%;
            height: 100%;
            background-color: #4CAF50;
        }
    </style>
</head>

<body>
    <div class="container">
        <h2>Client Purchase Prediction Model</h2>
        <input type="file" id="csvFile" accept=".csv" />
        <div id="progress" class="progress">
            <div id="progressBar" class="progress-bar"></div>
        </div>
        <div id="chart_div" style="width: 800px; height: 500px;"></div>
    </div>

    <script>
        // Load Google Charts
        google.charts.load('current', { 'packages': ['corechart'] });

        // Initialize variables
        let model;
        let normalizedData;
        let dates;

        // Handle file upload
        document.getElementById('csvFile').addEventListener('change', handleFileSelect);

        async function handleFileSelect(event) {
            try {
                const file = event.target.files[0];
                const text = await file.text();
                const data = parseCSV(text);
                await processData(data);
            } catch (error) {
                handleError(error);
            }
        }

        function parseCSV(text) {
            const lines = text.split('\n');
            const headers = lines[0].split(',');
            const data = [];

            for (let i = 1; i < lines.length; i++) {
                if (lines[i].trim() === '') continue;
                const values = lines[i].split(',');
                const row = {};
                row.date = values[0];
                row.features = values.slice(1, -1).map(Number);
                data.push(row);
            }
            return { headers, data };
        }

        async function processData(parsedData) {
            dates = parsedData.data.map(row => row.date);
            const features = parsedData.data.map(row => row.features);

            // Normalize features
            normalizedData = normalizeFeatures(features);

            // Create and train model
            await createAndTrainModel(normalizedData);
        }

        function normalizeFeatures(features) {
            const tensorData = tf.tensor2d(features);
            const min = tensorData.min(0);
            const max = tensorData.max(0);
            return tensorData.sub(min).div(max.sub(min));
        }

        async function createAndTrainModel(normalizedData) {
            // Create model with multiple layers
            model = tf.sequential();
            model.add(tf.layers.dense({
                units: 16,
                activation: 'relu',
                inputShape: [normalizedData.shape[1]]
            }));
            model.add(tf.layers.dense({
                units: 8,
                activation: 'relu'
            }));
            model.add(tf.layers.dense({
                units: 1,
                activation: 'sigmoid'
            }));

            // Compile model
            model.compile({
                optimizer: tf.train.adam(0.01),
                loss: 'binaryCrossentropy',
                metrics: ['accuracy']
            });

            // Train model
            const epochs = 100;
            await trainModel(normalizedData, epochs);
        }

        async function trainModel(normalizedData, epochs) {
            const progressBar = document.getElementById('progressBar');

            try {
                await model.fit(normalizedData, normalizedData, {
                    epochs: epochs,
                    callbacks: {
                        onEpochEnd: (epoch, logs) => {
                            // Update progress bar
                            const progress = ((epoch + 1) / epochs) * 100;
                            progressBar.style.width = progress + '%';
                        }
                    }
                });

                // Make predictions after training
                makePredictions(normalizedData);
            } catch (error) {
                handleError(error);
            }
        }

        async function makePredictions(normalizedData) {
            try {
                const predictions = model.predict(normalizedData);
                const predictionData = await predictions.data();
                drawChart(predictionData);
            } catch (error) {
                handleError(error);
            }
        }

        function drawChart(predictions) {
            const data = new google.visualization.DataTable();
            data.addColumn('number', 'Client');
            data.addColumn('number', 'Prediction');

            // Prepare data for chart
            const chartData = predictions.map((pred, index) => {
                return [index + 1, pred];
            });

            data.addRows(chartData);

            const options = {
                title: 'Client Purchase Predictions',
                hAxis: {
                    title: 'Client Number',
                    minValue: 0,
                    maxValue: predictions.length + 1
                },
                vAxis: {
                    title: 'Prediction Probability',
                    minValue: 0,
                    maxValue: 1
                },
                legend: 'none',
                pointSize: 5
            };

            const chart = new google.visualization.ScatterChart(
                document.getElementById('chart_div')
            );

            chart.draw(data, options);
        }

        function handleError(error) {
            console.error('Error:', error);
            alert('An error occurred: ' + error.message);
        }
    </script>
</body>

</html>