File size: 2,890 Bytes
bb5be95
 
 
 
 
 
 
 
 
 
0e40a98
bb5be95
 
 
0e40a98
bb5be95
 
 
 
0e40a98
bb5be95
 
 
 
 
 
0e40a98
bb5be95
 
 
 
 
 
 
 
 
 
 
0e40a98
bb5be95
 
 
 
 
 
 
 
 
 
0e40a98
bb5be95
 
 
 
 
 
0e40a98
bb5be95
0e40a98
bb5be95
 
 
 
 
0e40a98
bb5be95
 
0e40a98
bb5be95
 
 
 
0e40a98
bb5be95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<html>
<head>
    <title>Skin Disease Detection</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f9ff;
            text-align: center;
        }

        h2 {
            color: #1e3a8a;
        }

        .container {
            position: relative;
            display: inline-block;
        }

        video, img {
            width: 640px;
            height: 480px;
            border-radius: 12px;
            border: 3px solid #1e3a8a;
        }

        #loading {
            position: absolute;
            top: 10px;
            left: 10px;
            background: rgba(0, 0, 0, 0.6);
            color: white;
            padding: 6px 12px;
            border-radius: 8px;
            font-size: 14px;
            display: none;
        }

        button {
            margin-top: 15px;
            padding: 10px 20px;
            font-size: 16px;
            border-radius: 8px;
            border: none;
            background-color: #1e3a8a;
            color: white;
            cursor: pointer;
        }

        button:hover {
            background-color: #162d6b;
        }
    </style>
</head>
<body>

<h2>Live Skin Disease Detection</h2>

<div class="container">
    <video id="video" autoplay muted></video>
    <img id="output" />
    <div id="loading">Detecting...</div>
</div>

<br>
<button onclick="startDetection()">Start Detection</button>

<script>
const video = document.getElementById("video");
const output = document.getElementById("output");
const loading = document.getElementById("loading");

let detectionInterval = null;

// Start camera
navigator.mediaDevices.getUserMedia({ video: true })
    .then(stream => {
        video.srcObject = stream;
    })
    .catch(err => {
        alert("Camera access denied or not available.");
    });

async function sendFrame() {
    if (video.readyState !== 4) return;

    loading.style.display = "block";

    const canvas = document.createElement("canvas");
    canvas.width = 480;
    canvas.height = 360;

    const ctx = canvas.getContext("2d");
    ctx.drawImage(video, 0, 0, canvas.width, canvas.height);

    const blob = await new Promise(resolve =>
        canvas.toBlob(resolve, "image/jpeg", 0.6) // Compress upload
    );

    const formData = new FormData();
    formData.append("file", blob);

    try {
        const response = await fetch("/detect", {
            method: "POST",
            body: formData
        });

        const imageBlob = await response.blob();
        output.src = URL.createObjectURL(imageBlob);
    } catch (error) {
        console.error("Detection error:", error);
    }

    loading.style.display = "none";
}

function startDetection() {
    if (detectionInterval) return;

    detectionInterval = setInterval(sendFrame, 600); // 1.5–2 FPS smooth on HF
}
</script>

</body>
</html>