File size: 1,652 Bytes
cbe52f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Image Classification</title>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.9.0/dist/tf.min.js"></script>
</head>
<body>
    <h1>Image Classification</h1>
    <input type="file" id="imageInput" accept="image/*">
    <img id="inputImage" src="#" alt="Input Image" style="max-width: 300px; max-height: 300px;">
    <button onclick="classifyImage()">Classify</button>
    <div id="output"></div>

    <script>
        async function classifyImage() {
            const file = document.getElementById('imageInput').files[0];
            const formData = new FormData();
            formData.append('file', file);
            
            const response = await fetch('http://localhost:5000/classify', {
                method: 'POST',
                body: formData
            });
            const result = await response.json();
            
            const outputElement = document.getElementById('output');
            outputElement.innerHTML = '<h2>Predictions:</h2>';
            result.predictions.forEach(prediction => {
                outputElement.innerHTML += `<p>${prediction.className}: ${prediction.probability.toFixed(4)}</p>`;
            });
        }

        document.getElementById('imageInput').addEventListener('change', function(event) {
            const file = event.target.files[0];
            const imageElement = document.getElementById('inputImage');
            imageElement.src = URL.createObjectURL(file);
        });
    </script>
</body>
</html>