dal4933 commited on
Commit
780879e
·
verified ·
1 Parent(s): 6828656

Delete static

Browse files
Files changed (1) hide show
  1. static/index.html +0 -137
static/index.html DELETED
@@ -1,137 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Webcam Object Detector</title>
5
- <style>
6
- body {
7
- font-family: Arial, sans-serif;
8
- max-width: 800px;
9
- margin: 0 auto;
10
- padding: 20px;
11
- }
12
- #videoContainer {
13
- position: relative;
14
- margin-bottom: 20px;
15
- }
16
- #liveVideo {
17
- border: 2px solid #333;
18
- border-radius: 4px;
19
- }
20
- #results {
21
- background: #f5f5f5;
22
- padding: 15px;
23
- border-radius: 4px;
24
- white-space: pre-wrap;
25
- font-family: monospace;
26
- }
27
- button {
28
- padding: 10px 20px;
29
- background: #007bff;
30
- color: white;
31
- border: none;
32
- border-radius: 4px;
33
- cursor: pointer;
34
- margin: 10px 0;
35
- }
36
- button:hover {
37
- background: #0056b3;
38
- }
39
- </style>
40
- </head>
41
- <body>
42
- <h1>Webcam Object Detection</h1>
43
-
44
- <div id="videoContainer">
45
- <video id="liveVideo" width="640" height="480" autoplay></video>
46
- <div>
47
- <button id="toggleBtn">Start Detection</button>
48
- </div>
49
- </div>
50
-
51
- <div id="results">Detection results will appear here...</div>
52
-
53
- <script>
54
- const video = document.getElementById('liveVideo');
55
- const toggleBtn = document.getElementById('toggleBtn');
56
- const resultsDiv = document.getElementById('results');
57
- let isDetecting = false;
58
- let intervalId = null;
59
- let mediaStream = null;
60
-
61
- // Setup webcam
62
- async function setupWebcam() {
63
- try {
64
- mediaStream = await navigator.mediaDevices.getUserMedia({ video: true });
65
- video.srcObject = mediaStream;
66
- toggleBtn.disabled = false;
67
- } catch (err) {
68
- resultsDiv.textContent = `Error accessing webcam: ${err.message}`;
69
- }
70
- }
71
-
72
- // Capture frame from video
73
- function captureFrame() {
74
- const canvas = document.createElement('canvas');
75
- canvas.width = video.videoWidth;
76
- canvas.height = video.videoHeight;
77
- canvas.getContext('2d').drawImage(video, 0, 0);
78
-
79
- return new Promise((resolve) => {
80
- canvas.toBlob(resolve, 'image/jpeg', 0.8);
81
- });
82
- }
83
-
84
- // Send frame to API
85
- async function sendFrame() {
86
- try {
87
- const blob = await captureFrame();
88
- const formData = new FormData();
89
- formData.append('file', blob, 'frame.jpg');
90
-
91
- const response = await fetch('/detect', {
92
- method: 'POST',
93
- body: formData
94
- });
95
-
96
- const data = await response.json();
97
-
98
- if (data.detections) {
99
- resultsDiv.textContent = JSON.stringify(data.detections, null, 2);
100
- } else if (data.error) {
101
- resultsDiv.textContent = `Error: ${data.error}`;
102
- }
103
- } catch (err) {
104
- resultsDiv.textContent = `Request failed: ${err.message}`;
105
- }
106
- }
107
-
108
- // Toggle detection
109
- function toggleDetection() {
110
- if (!isDetecting) {
111
- isDetecting = true;
112
- toggleBtn.textContent = 'Stop Detection';
113
- intervalId = setInterval(sendFrame, 100); // Send every 2 seconds
114
- } else {
115
- isDetecting = false;
116
- toggleBtn.textContent = 'Start Detection';
117
- clearInterval(intervalId);
118
- resultsDiv.textContent = 'Detection stopped';
119
- }
120
- }
121
-
122
- // Cleanup webcam
123
- function stopWebcam() {
124
- if (mediaStream) {
125
- mediaStream.getTracks().forEach(track => track.stop());
126
- }
127
- }
128
-
129
- // Event listeners
130
- toggleBtn.addEventListener('click', toggleDetection);
131
- window.addEventListener('beforeunload', stopWebcam);
132
-
133
- // Initialize
134
- setupWebcam();
135
- </script>
136
- </body>
137
- </html>