Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +60 -39
templates/index.html
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<meta charset="utf-8" />
|
@@ -23,11 +22,11 @@
|
|
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,14 +47,22 @@
|
|
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
|
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,50 +73,42 @@
|
|
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="
|
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
|
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 =
|
92 |
-
ramDisplay.innerText =
|
93 |
-
cpuCircle.style.background =
|
94 |
-
ramCircle.style.background =
|
95 |
});
|
96 |
}, 10000);
|
97 |
-
|
98 |
-
// Get camera list
|
99 |
navigator.mediaDevices.enumerateDevices().then((devices) => {
|
100 |
devices.forEach((device) => {
|
101 |
if (device.kind === "videoinput") {
|
102 |
let option = document.createElement("option");
|
103 |
option.value = device.deviceId;
|
104 |
-
option.text = device.label ||
|
105 |
cameraSelect.appendChild(option);
|
106 |
}
|
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,
|
@@ -119,25 +118,47 @@
|
|
119 |
videoElement.srcObject = stream;
|
120 |
});
|
121 |
}
|
122 |
-
|
123 |
-
// Start/Stop detection
|
124 |
function startDetection() {
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
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>
|
|
|
|
|
1 |
<html lang="en">
|
2 |
<head>
|
3 |
<meta charset="utf-8" />
|
|
|
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 |
<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 |
<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 |
+
let metricInterval = setInterval(() => {
|
|
|
|
|
|
|
|
|
|
|
89 |
fetch("/sysInfo")
|
90 |
.then((response) => response.json())
|
91 |
.then((data) => {
|
92 |
+
cpuDisplay.innerText = CPU usage : ${data.cpu}%;
|
93 |
+
ramDisplay.innerText = RAM usage : ${data.ram}%;
|
94 |
+
cpuCircle.style.background = conic-gradient(#0ea5e9 ${data.cpu}%, #082f49 ${data.cpu}%);
|
95 |
+
ramCircle.style.background = conic-gradient(#0ea5e9 ${data.ram}%, #082f49 ${data.ram}%);
|
96 |
});
|
97 |
}, 10000);
|
98 |
+
// get camera list from browser
|
|
|
99 |
navigator.mediaDevices.enumerateDevices().then((devices) => {
|
100 |
devices.forEach((device) => {
|
101 |
if (device.kind === "videoinput") {
|
102 |
let option = document.createElement("option");
|
103 |
option.value = device.deviceId;
|
104 |
+
option.text = device.label || Camera ${cameraSelect.options.length + 1};
|
105 |
cameraSelect.appendChild(option);
|
106 |
}
|
107 |
});
|
108 |
});
|
|
|
|
|
109 |
function CameraSelector(event) {
|
110 |
let cameraId = event.target.value;
|
111 |
+
let videoElement = document.getElementById("videoElement");
|
112 |
let constraints = {
|
113 |
video: {
|
114 |
deviceId: cameraId ? { exact: cameraId } : undefined,
|
|
|
118 |
videoElement.srcObject = stream;
|
119 |
});
|
120 |
}
|
121 |
+
window.ProcessStatus = false;
|
|
|
122 |
function startDetection() {
|
123 |
+
if (window.ProcessStatus == false) {
|
124 |
+
window.ProcessStatus = true;
|
125 |
+
document.getElementById("startStop").innerText = "Stop";
|
126 |
+
}
|
127 |
+
else {
|
128 |
+
window.ProcessStatus = false;
|
129 |
+
document.getElementById("startStop").innerText = "Start";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
}
|
131 |
+
if (window.ProcessStatus) {
|
132 |
+
let videoElement = document.getElementById("videoElement");
|
133 |
+
let output = document.getElementById("ouptut");
|
134 |
+
let newCanvas = document.createElement("canvas");
|
135 |
+
let model = document.getElementById("model").value;
|
136 |
+
newCanvas.width = videoElement.videoWidth;
|
137 |
+
newCanvas.height = videoElement.videoHeight;
|
138 |
+
iterator(newCanvas,videoElement,output)
|
139 |
+
}
|
140 |
+
}
|
141 |
+
function iterator(newCanvas,videoElement,output) {
|
142 |
+
let ctx = newCanvas.getContext("2d");
|
143 |
+
ctx.drawImage(videoElement, 0, 0, newCanvas.width, newCanvas.height);
|
144 |
+
let formdata = new FormData();
|
145 |
+
formdata.append("image", newCanvas.toDataURL("image/jpeg"));
|
146 |
+
formdata.append("model", document.getElementById("model").value);
|
147 |
+
fetch("/processor", {
|
148 |
+
method: "POST",
|
149 |
+
body: formdata,
|
150 |
+
redirect: "follow"
|
151 |
+
})
|
152 |
+
.then((response) => response.json())
|
153 |
+
.then((data) => {
|
154 |
+
output.src = "data:image/jpeg;base64,"+data.image
|
155 |
+
})
|
156 |
+
.catch((error) => console.error("Error:", error))
|
157 |
+
.finally(() => {
|
158 |
+
if (window.ProcessStatus) {
|
159 |
+
iterator(newCanvas,videoElement,output)
|
160 |
+
}
|
161 |
+
});
|
162 |
}
|
163 |
</script>
|
164 |
</body>
|