srivatsavdamaraju commited on
Commit
322caed
·
verified ·
1 Parent(s): 9b02fee

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +184 -17
index.html CHANGED
@@ -1,19 +1,186 @@
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>AI Night Vision Camera</title>
5
+ <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
6
+ <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd"></script>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ background: #000;
11
+ color: #fff;
12
+ font-family: monospace;
13
+ }
14
+ .container {
15
+ max-width: 1200px;
16
+ margin: 0 auto;
17
+ padding: 20px;
18
+ display: flex;
19
+ flex-direction: column;
20
+ align-items: center;
21
+ }
22
+ .video-container {
23
+ position: relative;
24
+ width: 640px;
25
+ height: 480px;
26
+ border: 2px solid #0f0;
27
+ border-radius: 8px;
28
+ overflow: hidden;
29
+ }
30
+ #video {
31
+ width: 100%;
32
+ height: 100%;
33
+ object-fit: cover;
34
+ transform: scaleX(-1);
35
+ }
36
+ #canvas {
37
+ position: absolute;
38
+ top: 0;
39
+ left: 0;
40
+ transform: scaleX(-1);
41
+ }
42
+ .detection-info {
43
+ margin-top: 20px;
44
+ padding: 10px;
45
+ background: rgba(0, 255, 0, 0.1);
46
+ border: 1px solid #0f0;
47
+ border-radius: 4px;
48
+ width: 100%;
49
+ max-width: 620px;
50
+ }
51
+ .stats {
52
+ display: flex;
53
+ justify-content: space-between;
54
+ margin-top: 10px;
55
+ font-size: 14px;
56
+ }
57
+ .detection-box {
58
+ position: absolute;
59
+ border: 2px solid #0f0;
60
+ background: rgba(0, 255, 0, 0.1);
61
+ }
62
+ .detection-label {
63
+ position: absolute;
64
+ top: -25px;
65
+ left: 0;
66
+ background: #0f0;
67
+ color: #000;
68
+ padding: 2px 6px;
69
+ font-size: 12px;
70
+ border-radius: 2px;
71
+ }
72
+ </style>
73
+ </head>
74
+ <body>
75
+ <div class="container">
76
+ <div class="video-container">
77
+ <video id="video" autoplay playsinline></video>
78
+ <canvas id="canvas"></canvas>
79
+ </div>
80
+
81
+ <div class="detection-info">
82
+ <div id="detections"></div>
83
+ <div class="stats">
84
+ <span id="fps">FPS: 0</span>
85
+ <span id="objects">Objects detected: 0</span>
86
+ </div>
87
+ </div>
88
+ </div>
89
+
90
+ <script>
91
+ let video = document.getElementById('video');
92
+ let canvas = document.getElementById('canvas');
93
+ let ctx = canvas.getContext('2d');
94
+ let model;
95
+ let lastTime = performance.now();
96
+ let frameCount = 0;
97
+
98
+ // Initialize camera and AI model
99
+ async function init() {
100
+ // Load COCO-SSD model
101
+ model = await cocoSsd.load();
102
+ // Setup camera
103
+ const constraints = {
104
+ video: {
105
+ width: 640,
106
+ height: 480,
107
+ facingMode: 'environment',
108
+ advanced: [{
109
+ exposureMode: 'manual',
110
+ exposureCompensation: 2
111
+ }]
112
+ }
113
+ };
114
+ const stream = await navigator.mediaDevices.getUserMedia(constraints);
115
+ video.srcObject = stream;
116
+ // Set canvas size
117
+ canvas.width = 640;
118
+ canvas.height = 480;
119
+ // Start detection loop
120
+ requestAnimationFrame(detect);
121
+ }
122
+
123
+ async function detect() {
124
+ // Calculate FPS
125
+ const now = performance.now();
126
+ frameCount++;
127
+ if (now - lastTime >= 1000) {
128
+ document.getElementById('fps').textContent = `FPS: ${frameCount}`;
129
+ frameCount = 0;
130
+ lastTime = now;
131
+ }
132
+
133
+ // Detect objects
134
+ const predictions = await model.detect(video);
135
+
136
+ // Clear previous detections
137
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
138
+
139
+ // Draw new detections
140
+ predictions.forEach(prediction => {
141
+ // Draw bounding box
142
+ ctx.strokeStyle = '#00ff00';
143
+ ctx.lineWidth = 2;
144
+ ctx.strokeRect(
145
+ prediction.bbox[0],
146
+ prediction.bbox[1],
147
+ prediction.bbox[2],
148
+ prediction.bbox[3]
149
+ );
150
+ // Draw label background
151
+ ctx.fillStyle = '#00ff00';
152
+ ctx.fillRect(
153
+ prediction.bbox[0],
154
+ prediction.bbox[1] - 20,
155
+ prediction.bbox[2],
156
+ 20
157
+ );
158
+ // Draw label text
159
+ ctx.fillStyle = '#000000';
160
+ ctx.font = '16px monospace';
161
+ ctx.fillText(
162
+ `${prediction.class} ${Math.round(prediction.score * 100)}%`,
163
+ prediction.bbox[0] + 5,
164
+ prediction.bbox[1] - 5
165
+ );
166
+ });
167
+
168
+ // Update detection info
169
+ document.getElementById('objects').textContent =
170
+ `Objects detected: ${predictions.length}`;
171
+
172
+ document.getElementById('detections').innerHTML =
173
+ predictions.map(p =>
174
+ `Detected ${p.class} (${Math.round(p.score * 100)}% confidence)`
175
+ ).join('<br>');
176
+
177
+ requestAnimationFrame(detect);
178
+ }
179
+
180
+ // Start application
181
+ init().catch(err => {
182
+ console.error('Error initializing camera:', err);
183
+ });
184
+ </script>
185
+ </body>
186
  </html>