Spaces:
Runtime error
Runtime error
Update index.html
Browse files- index.html +34 -110
index.html
CHANGED
|
@@ -3,144 +3,68 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<title>LiveKit Object Detection</title>
|
| 6 |
-
<
|
| 7 |
<style>
|
| 8 |
body {
|
| 9 |
-
|
| 10 |
-
background: linear-gradient(135deg, #2d2b52 0%, #191731 100%);
|
| 11 |
color: white;
|
| 12 |
-
|
| 13 |
-
padding: 20px;
|
| 14 |
-
height: 100vh;
|
| 15 |
-
box-sizing: border-box;
|
| 16 |
display: flex;
|
| 17 |
flex-direction: column;
|
| 18 |
align-items: center;
|
| 19 |
justify-content: center;
|
| 20 |
-
|
| 21 |
-
.container {
|
| 22 |
-
max-width: 800px;
|
| 23 |
-
text-align: center;
|
| 24 |
-
display: flex;
|
| 25 |
-
flex-direction: column;
|
| 26 |
-
align-items: center;
|
| 27 |
-
}
|
| 28 |
-
.video-container {
|
| 29 |
-
max-width: 500px;
|
| 30 |
-
aspect-ratio: 1/1;
|
| 31 |
-
background: rgba(255, 255, 255, 0.1);
|
| 32 |
-
border-radius: 12px;
|
| 33 |
-
overflow: hidden;
|
| 34 |
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
|
| 35 |
-
margin: 10px 0;
|
| 36 |
}
|
| 37 |
video {
|
| 38 |
-
width:
|
| 39 |
-
height:
|
| 40 |
-
|
| 41 |
-
}
|
| 42 |
-
button {
|
| 43 |
-
background: white;
|
| 44 |
-
color: #2d2b52;
|
| 45 |
-
border: none;
|
| 46 |
-
padding: 12px 32px;
|
| 47 |
-
border-radius: 24px;
|
| 48 |
-
font-size: 16px;
|
| 49 |
-
font-weight: 600;
|
| 50 |
-
cursor: pointer;
|
| 51 |
-
transition: all 0.3s ease;
|
| 52 |
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
| 53 |
-
}
|
| 54 |
-
button:hover {
|
| 55 |
-
transform: translateY(-2px);
|
| 56 |
-
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
|
| 57 |
}
|
| 58 |
-
.
|
| 59 |
-
|
| 60 |
-
margin-top: 16px;
|
| 61 |
}
|
| 62 |
input[type="range"] {
|
| 63 |
-
width:
|
| 64 |
-
}
|
| 65 |
-
label {
|
| 66 |
-
font-size: 14px;
|
| 67 |
}
|
| 68 |
</style>
|
| 69 |
</head>
|
| 70 |
<body>
|
| 71 |
-
<
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
<
|
| 75 |
-
|
| 76 |
-
</div>
|
| 77 |
-
<div class="slider-container">
|
| 78 |
-
<label>Confidence Threshold: <span id="conf-value">0.3</span></label>
|
| 79 |
-
<input type="range" id="conf-threshold" min="0" max="1" step="0.01" value="0.3">
|
| 80 |
-
</div>
|
| 81 |
-
<button id="start-button">Start Streaming</button>
|
| 82 |
</div>
|
| 83 |
|
| 84 |
-
<script
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
const startBtn = document.getElementById("start-button");
|
| 88 |
-
const video = document.getElementById("video");
|
| 89 |
const confSlider = document.getElementById("conf-threshold");
|
| 90 |
-
const
|
| 91 |
-
|
| 92 |
-
let room;
|
| 93 |
-
let intervalId;
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
|
| 99 |
-
|
| 100 |
-
const
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
room = await connect(livekitURL, token, {
|
| 104 |
-
video: true,
|
| 105 |
-
audio: false,
|
| 106 |
-
});
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
video.srcObject = stream;
|
| 112 |
-
|
| 113 |
-
// Send image frames to backend every 1 second
|
| 114 |
-
intervalId = setInterval(() => {
|
| 115 |
-
const canvas = document.createElement("canvas");
|
| 116 |
-
canvas.width = video.videoWidth;
|
| 117 |
-
canvas.height = video.videoHeight;
|
| 118 |
-
const ctx = canvas.getContext("2d");
|
| 119 |
-
ctx.drawImage(video, 0, 0);
|
| 120 |
-
const imageData = canvas.toDataURL("image/jpeg");
|
| 121 |
-
|
| 122 |
-
fetch("http://localhost:8000/detect", {
|
| 123 |
method: "POST",
|
| 124 |
headers: { "Content-Type": "application/json" },
|
| 125 |
body: JSON.stringify({
|
| 126 |
-
|
| 127 |
-
conf_threshold: parseFloat(
|
| 128 |
-
})
|
| 129 |
});
|
| 130 |
-
}
|
| 131 |
}
|
| 132 |
|
| 133 |
-
|
| 134 |
-
if (startBtn.textContent === "Start Streaming") {
|
| 135 |
-
await startStream();
|
| 136 |
-
startBtn.textContent = "Stop Streaming";
|
| 137 |
-
} else {
|
| 138 |
-
if (room) room.disconnect();
|
| 139 |
-
if (intervalId) clearInterval(intervalId);
|
| 140 |
-
video.srcObject = null;
|
| 141 |
-
startBtn.textContent = "Start Streaming";
|
| 142 |
-
}
|
| 143 |
-
});
|
| 144 |
</script>
|
| 145 |
</body>
|
| 146 |
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<title>LiveKit Object Detection</title>
|
| 6 |
+
<script src="https://cdn.livekit.io/livekit-client.min.js"></script>
|
| 7 |
<style>
|
| 8 |
body {
|
| 9 |
+
background: #191731;
|
|
|
|
| 10 |
color: white;
|
| 11 |
+
font-family: sans-serif;
|
|
|
|
|
|
|
|
|
|
| 12 |
display: flex;
|
| 13 |
flex-direction: column;
|
| 14 |
align-items: center;
|
| 15 |
justify-content: center;
|
| 16 |
+
height: 100vh;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
| 18 |
video {
|
| 19 |
+
width: 500px;
|
| 20 |
+
height: 500px;
|
| 21 |
+
background: #222;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
+
.controls {
|
| 24 |
+
margin-top: 20px;
|
|
|
|
| 25 |
}
|
| 26 |
input[type="range"] {
|
| 27 |
+
width: 300px;
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
</style>
|
| 30 |
</head>
|
| 31 |
<body>
|
| 32 |
+
<h1>Real-Time Detection with LiveKit</h1>
|
| 33 |
+
<video id="video-output" autoplay muted playsinline></video>
|
| 34 |
+
<div class="controls">
|
| 35 |
+
<label>Confidence Threshold: <span id="conf-value">0.3</span></label><br />
|
| 36 |
+
<input type="range" min="0" max="1" step="0.01" value="0.3" id="conf-threshold" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
</div>
|
| 38 |
|
| 39 |
+
<script>
|
| 40 |
+
const token = "__LIVEKIT_TOKEN__"; // Replace with server-side injection or hardcode for dev
|
|
|
|
|
|
|
|
|
|
| 41 |
const confSlider = document.getElementById("conf-threshold");
|
| 42 |
+
const confValue = document.getElementById("conf-value");
|
| 43 |
+
const videoOutput = document.getElementById("video-output");
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
async function startLiveKit() {
|
| 46 |
+
const room = new Livekit.Room();
|
| 47 |
+
await room.connect("wss://your-livekit-server-url", token);
|
| 48 |
|
| 49 |
+
const mediaStream = await navigator.mediaDevices.getUserMedia({ video: true });
|
| 50 |
+
const track = await Livekit.createLocalVideoTrack({ deviceId: mediaStream.getVideoTracks()[0].getSettings().deviceId });
|
| 51 |
+
await room.localParticipant.publishTrack(track);
|
| 52 |
+
videoOutput.srcObject = new MediaStream([track.mediaStreamTrack]);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
confSlider.addEventListener("input", (e) => {
|
| 55 |
+
confValue.textContent = e.target.value;
|
| 56 |
+
fetch("/input_hook", {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
method: "POST",
|
| 58 |
headers: { "Content-Type": "application/json" },
|
| 59 |
body: JSON.stringify({
|
| 60 |
+
webrtc_id: "livekit_user", // Static ID for now
|
| 61 |
+
conf_threshold: parseFloat(e.target.value),
|
| 62 |
+
}),
|
| 63 |
});
|
| 64 |
+
});
|
| 65 |
}
|
| 66 |
|
| 67 |
+
startLiveKit();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
</script>
|
| 69 |
</body>
|
| 70 |
</html>
|