thejagstudio commited on
Commit
7816fde
·
verified ·
1 Parent(s): 36505bb

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +33 -60
templates/index.html CHANGED
@@ -1,3 +1,4 @@
 
1
  <html lang="en">
2
  <head>
3
  <meta charset="utf-8" />
@@ -22,11 +23,11 @@
22
  <div class="flex items-center gap-2">
23
  <div id="cpuCircle" class="h-10 w-10 group rounded-full flex items-center justify-center relative" style="background: conic-gradient(#0ea5e9 54deg, #082f49 54deg)">
24
  <div class="h-8 w-8 rounded-full bg-sky-900 text-white p-2 text-xs flex item-center justify-center">CPU</div>
25
- <div id="cpuDisplay" class="absolute scale-y-0 group-hover:scale-y-100 -translate-y-1/2 origin-top text-sm text-white top-14 bg-sky-800 w-max rounded-md px-2 transition-all">CPU usage : 15%</div>
26
  </div>
27
  <div id="ramCircle" class="h-10 w-10 group rounded-full flex items-center justify-center relative" style="background: conic-gradient(#0ea5e9 54deg, #082f49 54deg)">
28
  <div class="h-8 w-8 rounded-full bg-sky-900 text-white p-2 text-xs flex item-center justify-center">RAM</div>
29
- <div id="ramDisplay" class="absolute right-0 scale-y-0 group-hover:scale-y-100 -translate-y-1/2 origin-top text-sm text-white top-14 bg-sky-800 w-max rounded-md px-2 transition-all">RAM usage : 15%</div>
30
  </div>
31
  </div>
32
  </header>
@@ -47,22 +48,14 @@
47
  <option value="yolov10n.engine">Yolov10n Engine</option>
48
  <option value="FabricScanV1-seg.pt">FabricScan v1</option>
49
  </select>
50
- <span class="pointer-events-none absolute flex h-full w-10 items-center justify-center text-secondary-700 peer-focus:text-secondary dark:text-navy-300 dark:peer-focus:text-accent">
51
- <svg fill="currentColor" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
52
- <path d="M72.7,65.8a6.6,6.6,0,0,0-3.2.8l-8.8-6.5a11.36,11.36,0,0,0,1.2-5.2A11.91,11.91,0,0,0,53,43.4v-10a7,7,0,0,0,4-6.2,6.9,6.9,0,1,0-13.8,0,6.73,6.73,0,0,0,4,6.2v10a11.91,11.91,0,0,0-8.9,11.5,11.36,11.36,0,0,0,1.2,5.2l-8.8,6.5a7.22,7.22,0,0,0-3.2-.8,6.9,6.9,0,1,0,6.9,6.9c0-.5-.1-.9-.1-1.3l9.2-6.8a11.61,11.61,0,0,0,13.6,0l9.2,6.8a5.7,5.7,0,0,0-.1,1.3,6.9,6.9,0,0,0,13.8,0A7.41,7.41,0,0,0,72.7,65.8ZM51.4,60.7a6.75,6.75,0,0,1-1.4.2,6.1,6.1,0,0,1-5.7-4.4,7.72,7.72,0,0,1-.2-1.5,5.81,5.81,0,0,1,3-5.1,6,6,0,0,1,6,0,5.81,5.81,0,0,1,3,5.1,7.72,7.72,0,0,1-.2,1.5A6.54,6.54,0,0,1,51.4,60.7Z"></path>
53
- </svg>
54
- </span>
55
  </span>
56
  </div>
57
- <div class="block text-sm" title="Select a model">
58
  <span>Cameras</span>
59
  <div class="relative mt-1.5 flex gap-2">
60
- <select onchange="CameraSelector(event)" required="" id="cameraSelect" name="cameraSelect" class="form-input outline-none peer w-full rounded-lg border border-slate-300 bg-white text-black px-3 py-2 pl-9 placeholder:font-light hover:border-secondary-700 focus:border-secondary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent">
61
  <option value="null">--Select Camera--</option>
62
  </select>
63
- <span class="pointer-events-none absolute flex h-full w-10 items-center justify-center text-secondary-700 peer-focus:text-secondary dark:text-navy-300 dark:peer-focus:text-accent">
64
- <svg fill="currentColor" width="1.2em" height="1.2em" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><path d="M72.7,65.8a6.6,6.6,0,0,0-3.2.8l-8.8-6.5a11.36,11.36,0,0,0,1.2-5.2A11.91,11.91,0,0,0,53,43.4v-10a7,7,0,0,0,4-6.2,6.9,6.9,0,1,0-13.8,0,6.73,6.73,0,0,0,4,6.2v10a11.91,11.91,0,0,0-8.9,11.5,11.36,11.36,0,0,0,1.2,5.2l-8.8,6.5a7.22,7.22,0,0,0-3.2-.8,6.9,6.9,0,1,0,6.9,6.9c0-.5-.1-.9-.1-1.3l9.2-6.8a11.61,11.61,0,0,0,13.6,0l9.2,6.8a5.7,5.7,0,0,0-.1,1.3,6.9,6.9,0,0,0,13.8,0A7.41,7.41,0,0,0,72.7,65.8ZM51.4,60.7a6.75,6.75,0,0,1-1.4.2,6.1,6.1,0,0,1-5.7-4.4,7.72,7.72,0,0,1-.2-1.5,5.81,5.81,0,0,1,3-5.1,6,6,0,0,1,6,0,5.81,5.81,0,0,1,3,5.1,7.72,7.72,0,0,1-.2,1.5A6.54,6.54,0,0,1,51.4,60.7Z"></path></svg>
65
- </span>
66
  </div>
67
  </div>
68
  </div>
@@ -73,31 +66,36 @@
73
  <div class="grid grid-cols-1 lg:grid-cols-2 gap-5 mt-10">
74
  <div class="border border-sky-500 rounded-lg overflow-hidden relative">
75
  <video id="videoElement" class="w-full h-full rounded-lg" autoplay playsinline></video>
76
- <img id="ouptut" class="w-full h-full scale-100 rounded-lg absolute top-0 left-0"></video>
77
  </div>
78
  </div>
79
  </div>
80
  </div>
81
  </div>
 
82
  <script>
83
  let cpuCircle = document.getElementById("cpuCircle");
84
  let cpuDisplay = document.getElementById("cpuDisplay");
85
  let ramCircle = document.getElementById("ramCircle");
86
  let ramDisplay = document.getElementById("ramDisplay");
87
  let cameraSelect = document.getElementById("cameraSelect");
 
 
 
88
 
89
- let metricInterval = setInterval(() => {
 
90
  fetch("/sysInfo")
91
  .then((response) => response.json())
92
  .then((data) => {
93
- cpuDisplay.innerText = `CPU usage : ${data.cpu}%`;
94
- ramDisplay.innerText = `RAM usage : ${data.ram}%`;
95
  cpuCircle.style.background = `conic-gradient(#0ea5e9 ${data.cpu}%, #082f49 ${data.cpu}%)`;
96
  ramCircle.style.background = `conic-gradient(#0ea5e9 ${data.ram}%, #082f49 ${data.ram}%)`;
97
  });
98
  }, 10000);
99
 
100
- // get camera list from browser
101
  navigator.mediaDevices.enumerateDevices().then((devices) => {
102
  devices.forEach((device) => {
103
  if (device.kind === "videoinput") {
@@ -109,9 +107,9 @@
109
  });
110
  });
111
 
 
112
  function CameraSelector(event) {
113
  let cameraId = event.target.value;
114
- let videoElement = document.getElementById("videoElement");
115
  let constraints = {
116
  video: {
117
  deviceId: cameraId ? { exact: cameraId } : undefined,
@@ -122,50 +120,25 @@
122
  });
123
  }
124
 
125
- window.ProcessStatus = false;
126
-
127
  function startDetection() {
128
- if (window.ProcessStatus == false) {
129
- window.ProcessStatus = true;
130
- document.getElementById("startStop").innerText = "Stop";
131
- }
132
- else {
133
- window.ProcessStatus = false;
134
- document.getElementById("startStop").innerText = "Start";
135
- }
136
- if (window.ProcessStatus) {
137
- let videoElement = document.getElementById("videoElement");
138
- let output = document.getElementById("ouptut");
139
- let newCanvas = document.createElement("canvas");
140
- let model = document.getElementById("model").value;
141
- newCanvas.width = videoElement.videoWidth;
142
- newCanvas.height = videoElement.videoHeight;
143
- iterator(newCanvas,videoElement,output)
144
  }
145
-
146
- }
147
- function iterator(newCanvas,videoElement,output) {
148
- let ctx = newCanvas.getContext("2d");
149
- ctx.drawImage(videoElement, 0, 0, newCanvas.width, newCanvas.height);
150
- let formdata = new FormData();
151
- formdata.append("image", newCanvas.toDataURL("image/jpeg"));
152
- formdata.append("model", document.getElementById("model").value);
153
- fetch("/processor", {
154
- method: "POST",
155
- body: formdata,
156
- redirect: "follow"
157
- })
158
- .then((response) => response.json())
159
- .then((data) => {
160
- output.src = "data:image/jpeg;base64,"+data.image
161
- })
162
- .catch((error) => console.error("Error:", error))
163
- .finally(() => {
164
- if (window.ProcessStatus) {
165
- iterator(newCanvas,videoElement,output)
166
- }
167
- });
168
  }
169
  </script>
170
  </body>
171
- </html>
 
1
+ <!DOCTYPE html>
2
  <html lang="en">
3
  <head>
4
  <meta charset="utf-8" />
 
23
  <div class="flex items-center gap-2">
24
  <div id="cpuCircle" class="h-10 w-10 group rounded-full flex items-center justify-center relative" style="background: conic-gradient(#0ea5e9 54deg, #082f49 54deg)">
25
  <div class="h-8 w-8 rounded-full bg-sky-900 text-white p-2 text-xs flex item-center justify-center">CPU</div>
26
+ <div id="cpuDisplay" class="absolute scale-y-0 group-hover:scale-y-100 -translate-y-1/2 origin-top text-sm text-white top-14 bg-sky-800 w-max rounded-md px-2 transition-all">CPU usage: 15%</div>
27
  </div>
28
  <div id="ramCircle" class="h-10 w-10 group rounded-full flex items-center justify-center relative" style="background: conic-gradient(#0ea5e9 54deg, #082f49 54deg)">
29
  <div class="h-8 w-8 rounded-full bg-sky-900 text-white p-2 text-xs flex item-center justify-center">RAM</div>
30
+ <div id="ramDisplay" class="absolute right-0 scale-y-0 group-hover:scale-y-100 -translate-y-1/2 origin-top text-sm text-white top-14 bg-sky-800 w-max rounded-md px-2 transition-all">RAM usage: 15%</div>
31
  </div>
32
  </div>
33
  </header>
 
48
  <option value="yolov10n.engine">Yolov10n Engine</option>
49
  <option value="FabricScanV1-seg.pt">FabricScan v1</option>
50
  </select>
 
 
 
 
 
51
  </span>
52
  </div>
53
+ <div class="block text-sm" title="Select a camera">
54
  <span>Cameras</span>
55
  <div class="relative mt-1.5 flex gap-2">
56
+ <select onchange="CameraSelector(event)" required="" id="cameraSelect" name="cameraSelect" class="form-input outline-none peer w-full rounded-lg border border-slate-300 bg-white text-black px-3 py-2 pl-9 placeholder:font-light">
57
  <option value="null">--Select Camera--</option>
58
  </select>
 
 
 
59
  </div>
60
  </div>
61
  </div>
 
66
  <div class="grid grid-cols-1 lg:grid-cols-2 gap-5 mt-10">
67
  <div class="border border-sky-500 rounded-lg overflow-hidden relative">
68
  <video id="videoElement" class="w-full h-full rounded-lg" autoplay playsinline></video>
69
+ <img id="outputImage" class="w-full h-full scale-100 rounded-lg absolute top-0 left-0" />
70
  </div>
71
  </div>
72
  </div>
73
  </div>
74
  </div>
75
+
76
  <script>
77
  let cpuCircle = document.getElementById("cpuCircle");
78
  let cpuDisplay = document.getElementById("cpuDisplay");
79
  let ramCircle = document.getElementById("ramCircle");
80
  let ramDisplay = document.getElementById("ramDisplay");
81
  let cameraSelect = document.getElementById("cameraSelect");
82
+ let videoElement = document.getElementById("videoElement");
83
+ let outputImage = document.getElementById("outputImage");
84
+ let isProcessing = false;
85
 
86
+ // Update system metrics every 10 seconds
87
+ setInterval(() => {
88
  fetch("/sysInfo")
89
  .then((response) => response.json())
90
  .then((data) => {
91
+ cpuDisplay.innerText = `CPU usage: ${data.cpu}%`;
92
+ ramDisplay.innerText = `RAM usage: ${data.ram}%`;
93
  cpuCircle.style.background = `conic-gradient(#0ea5e9 ${data.cpu}%, #082f49 ${data.cpu}%)`;
94
  ramCircle.style.background = `conic-gradient(#0ea5e9 ${data.ram}%, #082f49 ${data.ram}%)`;
95
  });
96
  }, 10000);
97
 
98
+ // Get camera list
99
  navigator.mediaDevices.enumerateDevices().then((devices) => {
100
  devices.forEach((device) => {
101
  if (device.kind === "videoinput") {
 
107
  });
108
  });
109
 
110
+ // Camera selection handler
111
  function CameraSelector(event) {
112
  let cameraId = event.target.value;
 
113
  let constraints = {
114
  video: {
115
  deviceId: cameraId ? { exact: cameraId } : undefined,
 
120
  });
121
  }
122
 
123
+ // Start/Stop detection
 
124
  function startDetection() {
125
+ isProcessing = !isProcessing;
126
+ const startStopButton = document.getElementById("startStop");
127
+
128
+ if (isProcessing) {
129
+ startStopButton.innerText = "Stop";
130
+ fetch('/start_processing')
131
+ .then(() => {
132
+ outputImage.src = `/video_feed?${new Date().getTime()}`;
133
+ });
134
+ } else {
135
+ startStopButton.innerText = "Start";
136
+ fetch('/stop_processing')
137
+ .then(() => {
138
+ outputImage.src = '';
139
+ });
 
140
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
142
  </script>
143
  </body>
144
+ </html>