File size: 2,675 Bytes
897d6d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Brain Tumor Prediction</title>
    <style>

        body {

            font-family: Arial, sans-serif;

            background-color: #1e1e1e;

            color: #f5f5f5;

            text-align: center;

        }

        .container {

            margin: 20px auto;

            max-width: 800px;

            padding: 20px;

            background-color: #2c2c2c;

            border-radius: 10px;

        }

        h1 {

            color: #61dafb;

        }

        input[type="file"] {

            margin: 20px 0;

        }

        .result {

            margin: 20px 0;

        }

        .result img {

            max-width: 100%;

            border-radius: 10px;

        }

        .result p {

            font-size: 18px;

            margin: 10px 0;

        }

    </style>
</head>
<body>
    <div class="container">
        <h1>Brain Tumor Detection</h1>
        <form id="upload-form">
            <input type="file" id="file-input" accept="image/*" />
            <button type="submit">Upload and Predict</button>
        </form>
        <div class="result" id="result">
            <img id="input-image" src="" alt="Input Image" />
            <img id="mask-image" src="" alt="Predicted Mask Image" />
            <p id="class-label"></p>
            <p id="probability"></p>
        </div>
    </div>
    <script>

        document.getElementById('upload-form').onsubmit = async (e) => {

            e.preventDefault();

            

            const fileInput = document.getElementById('file-input');

            const file = fileInput.files[0];

            const formData = new FormData();

            formData.append('file', file);

            

            const response = await fetch('/predict', {

                method: 'POST',

                body: formData

            });

            const data = await response.json();

            

            if (data.error) {

                alert('Error: ' + data.error);

                return;

            }

            

            document.getElementById('input-image').src = 'data:image/png;base64,' + data.input_image;

            document.getElementById('mask-image').src = 'data:image/png;base64,' + data.mask_image;

            document.getElementById('class-label').innerText = 'Class Prediction: ' + data.class_label;

            document.getElementById('probability').innerText = 'Confidence: ' + (data.probability * 100).toFixed(2) + '%';

        };

    </script>
</body>
</html>