-
Notifications
You must be signed in to change notification settings - Fork 1
/
index-nanovlm.html
287 lines (267 loc) · 10.7 KB
/
index-nanovlm.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GenAI @ Edge</title>
<style>
/* Center the video frame */
#video-container {
text-align: center;
}
/* Adjust the width of the video frame */
#video-frame {
/* max-width: 100%; */
/* height: auto; */
height: 320px;
}
/* Adjust layout for text input and captured frame */
#chat-container {
display: flex;
justify-content: center;
align-items: center;
margin: 5px 0;
}
/* Style for captured frame */
#captured-frame {
/* width: 20%; */
border: 1px solid #000;
border-radius: 5px;
box-sizing: border-box; /* Ensure border width is included in width */
margin-top: 10px;
height: 400px;
}
#text-container {
max-width: 50%;
display: flex;
justify-content: center;
align-items: center;
}
/* Style for text input */
#data-chat {
width: 40%;
border: 2px solid #000;
border-radius: 5px;
box-sizing: border-box; /* Ensure border width is included in width */
margin-left: 10px;
margin-top: 10px;
overflow-y: auto;
height: 480px;
padding: 5px;
}
#data-input {
width: 50%;
border: 1px solid #000;
border-radius: 5px;
box-sizing: border-box; /* Ensure border width is included in width */
margin-top: 50px;
align-content: center;
left: 50%;
transform: translateX(-50%);
position: absolute;
height: 40px;
font-size: 30px;
}
/* Capture and Reset buttons */
#capture-reset-button {
width: 200px;
height: 50px;
font-size: 24px;
}
/* Send button style */
#send-button {
width: 200px;
height: 50px;
left: 50%;
transform: translateX(-50%);
position: absolute;
margin-top: 40px;
margin-bottom: 20px;
font-size: 24px;
}
/* Your existing CSS styles here */
#status-indicator {
width: 250px;
height: 50px;
border: 2px solid black;
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
margin-top: 10px;
}
</style>
</head>
<body>
<div id="video-container">
<h1>GenAI @ Edge: NanoVLM</h1>
<img id="video-frame" src="/Users/rpshah/Documents/GitHub/nanovlm-on-edge/frontend/placeholder.jpg" alt="Video Frame">
<br>
<button onclick="captureFrame()" id="capture-reset-button">Capture</button>
<button onclick="resetStream()" id="capture-reset-button">Reset</button>
</div>
<div id="chat-container">
<!-- <input type="text" id="data-chat" placeholder=""> -->
<img id="captured-frame" src="/Users/rpshah/Documents/GitHub/nanovlm-on-edge/frontend/placeholder.jpg" alt="Captured Frame will appear here.">
<div id="data-chat"></div>
</div>
<div id="text-container">
<input type="text" id="data-input" placeholder="Enter data...">
</div>
<br>
<button id="send-button" onclick="sendData()">Send</button>
<div id="status-indicator">Capture to Start</div>
<script>
var baseApiUrl = "API GATEWAY URL PLACEHOLDER";
// API Gateway endpoint URL
const apiUrlMqtt = baseApiUrl + "/mqtt";
const apiUrlVideo = baseApiUrl + "/video";
var apiGwHeaders = {
'Content-Type': 'application/json'
};
// Function to update status indicator
function updateStatusIndicator(statusText, color) {
const statusIndicator = document.getElementById('status-indicator');
statusIndicator.textContent = statusText;
statusIndicator.style.backgroundColor = color;
}
updateStatusIndicator('Capture to Start', 'white');
// Function to set the height of the data input field to match the captured frame
function setTextInputHeight() {
const capturedFrameHeight = document.getElementById('captured-frame').clientHeight;
document.getElementById('data-chat').style.height = capturedFrameHeight + 'px';
// Get the width of the window
const windowWidth = window.innerWidth;
// Get the width of the data input
const dataInputWidth = document.getElementById('data-chat').offsetWidth;
}
// Call setTextInputHeight initially and on window resize
window.onload = setTextInputHeight;
window.onresize = setTextInputHeight;
// Function to fetch and display the latest image
function fetchAndDisplayLatestImage() {
// Fetch the latest image from the API endpoint
fetch(apiUrlVideo)
.then(response => response.json())
.then(data => {
if (data.statusCode === 200) {
// Update the image source with the base64-encoded image data
document.getElementById('video-frame').src = 'data:image/jpeg;base64,' + data.body;
} else {
console.error('Error:', data.body);
}
})
.catch(error => console.error('Error fetching image:', error));
}
// Call fetchAndDisplayLatestImage initially
fetchAndDisplayLatestImage();
// Set up interval to fetch and update the image every second (adjust interval as needed)
setInterval(fetchAndDisplayLatestImage, 200); // 1000 milliseconds = 1 second
// Function to capture the current frame
function captureFrame() {
// Add your logic for capturing the frame here
const videoFrame = document.getElementById('video-frame');
// const capturedFrame = document.getElementById('captured-frame');
// capturedFrame.src = videoFrame.src;
var data = {
event: "capture",
type: "nanovlm"
}
// Invoke CAPTURE
fetch(apiUrlMqtt, {
method: 'POST',
headers: apiGwHeaders,
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
console.log('CAPTURE sent successfully!')
setTextInputHeight();
document.getElementById('captured-frame').src = 'data:image/jpeg;base64,' + data.body;
updateStatusIndicator('CAPTURE: Completed', 'cyan');
})
.catch(error => console.error('Error sending data:', error));
}
// Function to reset the stream
function resetStream() {
// Add your logic for resetting the stream here
console.log('Stream reset!');
var data = {
event: "reset",
type: "nanovlm"
}
// Invoke RESET
fetch(apiUrlMqtt, {
method: 'POST',
headers: apiGwHeaders,
body: JSON.stringify(data)
})
.then(() => {
console.log('RESET sent successfully!');
const capturedFrame = document.getElementById('captured-frame');
capturedFrame.src = '/Users/rpshah/Documents/GitHub/nanovlm-on-edge/frontend/placeholder.jpg';
const dataChat = document.getElementById('data-chat');
dataChat.innerHTML = '';
document.getElementById("data-input").value = "";
updateStatusIndicator('RESET: Capture to Start', 'white');
setTextInputHeight();
})
.catch(error => console.error('Error sending data:', error));
}
// Function to send data via API Gateway
function sendData() {
// Add your logic for sending data via API Gateway here
updateStatusIndicator('NanoVLM: Waiting for response', 'yellow');
const inputData = document.getElementById('data-input').value;
console.log('Data sent:', inputData);
var data = {
event: "text",
text: inputData,
type: "nanovlm"
}
updateTextBox('USER', inputData);
// Example of invoking an API Gateway endpoint without expecting a response
// Replace the URL with your actual API Gateway endpoint
fetch(apiUrlMqtt, {
method: 'POST',
headers: apiGwHeaders,
body: JSON.stringify(data)
})
.then(response => {
console.log('TEXT sent successfully!');
response.json().then(body => {
var messageData = JSON.parse(body.body).message;
updateTextBox('AI', messageData);
console.log('TEXT received successfully!');
updateStatusIndicator('NanoVLM: Response received', 'lightgreen');
document.getElementById("data-input").value = "";
});
setTextInputHeight();
})
.catch(error => console.error('Error sending data:', error));
}
// Function to update the textbox with sender and text color
function updateTextBox(sender, message) {
const dataChat = document.getElementById('data-chat');
const messageElement = document.createElement('p');
if (sender === 'USER') {
messageElement.style.color = 'blue';
} else if (sender === 'AI') {
messageElement.style.color = 'green';
} else {
// Handle other senders if needed
}
if (sender === 'USER' || sender === 'AI') {
const senderSpan = document.createElement('span');
senderSpan.style.color = sender === 'USER' ? 'black' : 'red';
senderSpan.textContent = sender + ' : ';
messageElement.appendChild(senderSpan);
}
messageElement.textContent += message;
dataChat.appendChild(messageElement);
// Scroll to the bottom of the chat container
dataChat.scrollTop = dataChat.scrollHeight;
}
</script>
</body>
</html>