| <!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; |
| |
| |
| 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) |
| ); |
| |
| 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); |
| } |
| </script> |
|
|
| </body> |
| </html> |