Prathamesh1420 commited on
Commit
35eb4d9
·
verified ·
1 Parent(s): 211452e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +49 -17
index.html CHANGED
@@ -1,19 +1,51 @@
1
- <!doctype html>
2
  <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
  <html>
3
+ <head>
4
+ <title>YOLOv8 Object Detection</title>
5
+ </head>
6
+ <body>
7
+ <h1>Webcam Object Detection with YOLOv8</h1>
8
+ <video id="video" width="640" height="480" autoplay></video>
9
+ <canvas id="canvas" style="display:none;"></canvas>
10
+ <br>
11
+ <img id="output" width="640" height="480" />
12
+
13
+ <script>
14
+ const video = document.getElementById('video');
15
+ const canvas = document.getElementById('canvas');
16
+ const ctx = canvas.getContext('2d');
17
+ const output = document.getElementById('output');
18
+
19
+ // Start webcam
20
+ navigator.mediaDevices.getUserMedia({ video: true }).then(stream => {
21
+ video.srcObject = stream;
22
+ });
23
+
24
+ // Send a frame every second to backend (flipped)
25
+ setInterval(() => {
26
+ canvas.width = video.videoWidth;
27
+ canvas.height = video.videoHeight;
28
+
29
+ // Flip the canvas horizontally
30
+ ctx.save();
31
+ ctx.scale(-1, 1);
32
+ ctx.drawImage(video, -canvas.width, 0, canvas.width, canvas.height);
33
+ ctx.restore();
34
+
35
+ const dataURL = canvas.toDataURL('image/jpeg');
36
+
37
+ fetch('/upload_frame', {
38
+ method: 'POST',
39
+ headers: { 'Content-Type': 'application/json' },
40
+ body: JSON.stringify({ image: dataURL })
41
+ })
42
+ .then(response => response.json())
43
+ .then(data => {
44
+ if (data.image) {
45
+ output.src = data.image;
46
+ }
47
+ });
48
+ }, 1000);
49
+ </script>
50
+ </body>
51
  </html>