Update index.html
Browse files- index.html +1 -394
index.html
CHANGED
@@ -1,394 +1 @@
|
|
1 |
-
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8">
|
5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Vision AI</title>
|
7 |
-
<link href="https://fonts.googleapis.com/css2?family=Inter+Tight:wght@300;400;500;600&display=swap" rel="stylesheet">
|
8 |
-
<script src="https://cdn.tailwindcss.com"></script>
|
9 |
-
<script>
|
10 |
-
tailwind.config = {
|
11 |
-
theme: {
|
12 |
-
extend: {
|
13 |
-
fontFamily: {
|
14 |
-
'inter-tight': ['Inter Tight', 'system-ui', 'sans-serif']
|
15 |
-
}
|
16 |
-
}
|
17 |
-
}
|
18 |
-
}
|
19 |
-
</script>
|
20 |
-
<style>
|
21 |
-
.loading-dots::after {
|
22 |
-
content: '';
|
23 |
-
display: inline-block;
|
24 |
-
animation: loading 1.5s infinite;
|
25 |
-
}
|
26 |
-
|
27 |
-
@keyframes loading {
|
28 |
-
0% { content: ''; }
|
29 |
-
25% { content: '.'; }
|
30 |
-
50% { content: '..'; }
|
31 |
-
75% { content: '...'; }
|
32 |
-
100% { content: ''; }
|
33 |
-
}
|
34 |
-
|
35 |
-
.drag-over {
|
36 |
-
@apply border-gray-900 bg-gray-50;
|
37 |
-
}
|
38 |
-
|
39 |
-
@keyframes slideIn {
|
40 |
-
from {
|
41 |
-
transform: translateX(100%);
|
42 |
-
opacity: 0;
|
43 |
-
}
|
44 |
-
to {
|
45 |
-
transform: translateX(0);
|
46 |
-
opacity: 1;
|
47 |
-
}
|
48 |
-
}
|
49 |
-
|
50 |
-
.notification {
|
51 |
-
animation: slideIn 0.3s ease;
|
52 |
-
}
|
53 |
-
|
54 |
-
textarea {
|
55 |
-
text-align: left !important;
|
56 |
-
direction: ltr !important;
|
57 |
-
}
|
58 |
-
|
59 |
-
#questionInput {
|
60 |
-
text-align: left !important;
|
61 |
-
}
|
62 |
-
</style>
|
63 |
-
</head>
|
64 |
-
<body class="min-h-screen bg-white text-gray-900 font-inter-tight antialiased">
|
65 |
-
<div class="max-w-2xl mx-auto px-6 py-12">
|
66 |
-
<!-- Header -->
|
67 |
-
<header class="mb-16">
|
68 |
-
<div class="flex items-center justify-between mb-8">
|
69 |
-
<div>
|
70 |
-
<h1 class="text-2xl font-semibold text-gray-900 tracking-tight">Vision AI</h1>
|
71 |
-
<p class="text-gray-600 text-sm mt-1">AI-powered image analysis</p>
|
72 |
-
</div>
|
73 |
-
<div class="w-2 h-2 bg-gray-900 rounded-full"></div>
|
74 |
-
</div>
|
75 |
-
</header>
|
76 |
-
|
77 |
-
<!-- Upload Section -->
|
78 |
-
<div class="mb-12">
|
79 |
-
<!-- Modified dropZone: relative for icon positioning, fixed height -->
|
80 |
-
<div id="dropZone" class="border-2 border-dashed border-gray-300 rounded-xl p-12 text-center cursor-pointer transition-all duration-200 hover:border-gray-900 hover:bg-gray-50 bg-gray-25 h-[300px] relative flex items-center justify-center">
|
81 |
-
<div id="dropContent" class="space-y-4">
|
82 |
-
<div class="mx-auto w-12 h-12 text-gray-400">
|
83 |
-
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" class="w-full h-full">
|
84 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/>
|
85 |
-
</svg>
|
86 |
-
</div>
|
87 |
-
<div>
|
88 |
-
<p class="text-gray-700 text-base font-medium mb-1">Drop your image here or click to browse</p>
|
89 |
-
<p class="text-gray-500 text-sm">Supports JPG, PNG, GIF up to 10MB</p>
|
90 |
-
</div>
|
91 |
-
</div>
|
92 |
-
|
93 |
-
<!-- Modified imagePreview: relative for icon positioning, flex column, full height/width -->
|
94 |
-
<div id="imagePreview" class="hidden absolute inset-0 flex-col">
|
95 |
-
<!-- Modified previewImg: object-contain to fit without cropping -->
|
96 |
-
<img id="previewImg" class="w-full h-full object-contain object-center" alt="Preview">
|
97 |
-
|
98 |
-
<!-- Cross Icon Button: absolute top-right -->
|
99 |
-
<button id="removeImage" class="absolute top-3 right-3 p-1.5 rounded-full bg-white/70 hover:bg-white/100 shadow-sm border border-gray-300 text-gray-700 hover:text-gray-900 transition-colors duration-200" aria-label="Remove image">
|
100 |
-
<!-- Heroicons X Mark Icon -->
|
101 |
-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
|
102 |
-
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" />
|
103 |
-
</svg>
|
104 |
-
</button>
|
105 |
-
</div>
|
106 |
-
</div>
|
107 |
-
|
108 |
-
<input type="file" id="fileInput" accept="image/*" class="hidden">
|
109 |
-
</div>
|
110 |
-
|
111 |
-
<!-- Question Section -->
|
112 |
-
<div class="mb-12 space-y-6">
|
113 |
-
<div>
|
114 |
-
<textarea
|
115 |
-
id="questionInput"
|
116 |
-
rows="4"
|
117 |
-
class="w-full px-4 py-3 border border-gray-300 rounded-lg resize-none focus:ring-2 focus:ring-gray-900 focus:border-transparent text-base placeholder-gray-500 transition-all duration-200 text-left"
|
118 |
-
placeholder="What would you like to know about this image?"
|
119 |
-
></textarea>
|
120 |
-
</div>
|
121 |
-
|
122 |
-
<button id="analyzeBtn" disabled class="w-full bg-gray-900 text-white px-6 py-4 rounded-lg font-medium text-base hover:bg-gray-800 disabled:bg-gray-300 disabled:text-gray-500 disabled:cursor-not-allowed transition-all duration-200 focus:ring-2 focus:ring-gray-900 focus:ring-offset-2">
|
123 |
-
<span id="analyzeText">Analyze Image</span>
|
124 |
-
</button>
|
125 |
-
</div>
|
126 |
-
|
127 |
-
<!-- Results Section -->
|
128 |
-
<div id="resultsSection" class="hidden mb-12">
|
129 |
-
<div class="border border-gray-200 rounded-xl p-8 bg-gray-50">
|
130 |
-
<div class="space-y-6">
|
131 |
-
<div>
|
132 |
-
<div class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2">Question</div>
|
133 |
-
<div class="text-gray-900 leading-relaxed" id="questionDisplay"></div>
|
134 |
-
</div>
|
135 |
-
|
136 |
-
<div>
|
137 |
-
<div class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2">Answer</div>
|
138 |
-
<div class="text-gray-900 leading-relaxed text-base" id="answerDisplay"></div>
|
139 |
-
</div>
|
140 |
-
|
141 |
-
<div class="flex justify-between items-center pt-4 border-t border-gray-200 text-xs text-gray-500">
|
142 |
-
<span>ID: <span id="requestId" class="font-mono"></span></span>
|
143 |
-
<span id="responseTime" class="font-medium"></span>
|
144 |
-
</div>
|
145 |
-
</div>
|
146 |
-
</div>
|
147 |
-
</div>
|
148 |
-
|
149 |
-
<!-- Footer -->
|
150 |
-
<footer class="pt-12 border-t border-gray-100">
|
151 |
-
<div class="flex items-center justify-between">
|
152 |
-
<p class="text-sm text-gray-500">
|
153 |
-
Powered by <a href="https://moondream.ai" target="_blank" class="text-gray-700 hover:text-gray-900 font-medium transition-colors duration-200 underline decoration-1 underline-offset-2">Moondream</a>
|
154 |
-
</p>
|
155 |
-
<div class="text-xs text-gray-400 font-mono">
|
156 |
-
v1.0.0
|
157 |
-
</div>
|
158 |
-
</div>
|
159 |
-
</footer>
|
160 |
-
</div>
|
161 |
-
|
162 |
-
<script>
|
163 |
-
class VisionApp {
|
164 |
-
constructor() {
|
165 |
-
// API key embedded in the app
|
166 |
-
// Note: Exposing API keys in client-side code is a security risk.
|
167 |
-
this.apiKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXlfaWQiOiJkMjc1N2QwNS04OGRjLTQ4YjUtOGVjNC05Y2M1ODYxYjBmOGMiLCJvcmdfaWQiOiIyUlJuZUVNMGVEblVRWFdjbDZKa3M3Y01vaWdTMmJ2aCIsImlhdCI6MTc1ODYyNzkzNywidmVyIjoxfQ.-Wqw1RXeev4ERwl18R9fefMzvOvSBVMvbVWiR3E-BOE';
|
168 |
-
this.currentImage = null;
|
169 |
-
this.initializeElements();
|
170 |
-
this.bindEvents();
|
171 |
-
}
|
172 |
-
|
173 |
-
initializeElements() {
|
174 |
-
this.elements = {
|
175 |
-
dropZone: document.getElementById('dropZone'),
|
176 |
-
fileInput: document.getElementById('fileInput'),
|
177 |
-
dropContent: document.getElementById('dropContent'),
|
178 |
-
imagePreview: document.getElementById('imagePreview'),
|
179 |
-
previewImg: document.getElementById('previewImg'),
|
180 |
-
removeImageBtn: document.getElementById('removeImage'), // Updated reference
|
181 |
-
questionInput: document.getElementById('questionInput'),
|
182 |
-
analyzeBtn: document.getElementById('analyzeBtn'),
|
183 |
-
analyzeText: document.getElementById('analyzeText'),
|
184 |
-
resultsSection: document.getElementById('resultsSection'),
|
185 |
-
questionDisplay: document.getElementById('questionDisplay'),
|
186 |
-
answerDisplay: document.getElementById('answerDisplay'),
|
187 |
-
requestId: document.getElementById('requestId'),
|
188 |
-
responseTime: document.getElementById('responseTime')
|
189 |
-
};
|
190 |
-
}
|
191 |
-
|
192 |
-
bindEvents() {
|
193 |
-
// File upload events
|
194 |
-
this.elements.dropZone.addEventListener('click', () => this.elements.fileInput.click());
|
195 |
-
this.elements.dropZone.addEventListener('dragover', this.handleDragOver.bind(this));
|
196 |
-
this.elements.dropZone.addEventListener('dragleave', this.handleDragLeave.bind(this));
|
197 |
-
this.elements.dropZone.addEventListener('drop', this.handleDrop.bind(this));
|
198 |
-
this.elements.fileInput.addEventListener('change', this.handleFileSelect.bind(this));
|
199 |
-
this.elements.removeImageBtn.addEventListener('click', (e) => {
|
200 |
-
e.stopPropagation(); // Prevent triggering drop zone click
|
201 |
-
this.removeImage();
|
202 |
-
});
|
203 |
-
|
204 |
-
// Question events
|
205 |
-
this.elements.questionInput.addEventListener('input', () => this.updateAnalyzeButton());
|
206 |
-
this.elements.analyzeBtn.addEventListener('click', () => this.analyzeImage());
|
207 |
-
}
|
208 |
-
|
209 |
-
handleDragOver(e) {
|
210 |
-
e.preventDefault();
|
211 |
-
this.elements.dropZone.classList.add('drag-over');
|
212 |
-
}
|
213 |
-
|
214 |
-
handleDragLeave(e) {
|
215 |
-
e.preventDefault();
|
216 |
-
if (!this.elements.dropZone.contains(e.relatedTarget)) {
|
217 |
-
this.elements.dropZone.classList.remove('drag-over');
|
218 |
-
}
|
219 |
-
}
|
220 |
-
|
221 |
-
handleDrop(e) {
|
222 |
-
e.preventDefault();
|
223 |
-
this.elements.dropZone.classList.remove('drag-over');
|
224 |
-
const files = e.dataTransfer.files;
|
225 |
-
if (files.length > 0) {
|
226 |
-
this.processFile(files[0]);
|
227 |
-
}
|
228 |
-
}
|
229 |
-
|
230 |
-
handleFileSelect(e) {
|
231 |
-
if (e.target.files.length > 0) {
|
232 |
-
this.processFile(e.target.files[0]);
|
233 |
-
}
|
234 |
-
}
|
235 |
-
|
236 |
-
processFile(file) {
|
237 |
-
if (!file.type.startsWith('image/')) {
|
238 |
-
this.showNotification('Please select a valid image file', 'error');
|
239 |
-
return;
|
240 |
-
}
|
241 |
-
|
242 |
-
if (file.size > 10 * 1024 * 1024) {
|
243 |
-
this.showNotification('File size should be less than 10MB', 'error');
|
244 |
-
return;
|
245 |
-
}
|
246 |
-
|
247 |
-
const reader = new FileReader();
|
248 |
-
reader.onload = (e) => {
|
249 |
-
this.currentImage = e.target.result;
|
250 |
-
this.showImagePreview(file);
|
251 |
-
};
|
252 |
-
reader.readAsDataURL(file);
|
253 |
-
}
|
254 |
-
|
255 |
-
showImagePreview(file) {
|
256 |
-
this.elements.previewImg.src = this.currentImage;
|
257 |
-
// this.elements.fileName.textContent = file.name; // Removed filename display
|
258 |
-
this.elements.dropContent.classList.add('hidden');
|
259 |
-
this.elements.imagePreview.classList.remove('hidden');
|
260 |
-
this.updateAnalyzeButton();
|
261 |
-
}
|
262 |
-
|
263 |
-
removeImage() {
|
264 |
-
this.currentImage = null;
|
265 |
-
this.elements.dropContent.classList.remove('hidden');
|
266 |
-
this.elements.imagePreview.classList.add('hidden');
|
267 |
-
this.elements.fileInput.value = '';
|
268 |
-
this.updateAnalyzeButton();
|
269 |
-
}
|
270 |
-
|
271 |
-
updateAnalyzeButton() {
|
272 |
-
const hasImage = this.currentImage !== null;
|
273 |
-
const hasQuestion = this.elements.questionInput.value.trim().length > 0;
|
274 |
-
|
275 |
-
this.elements.analyzeBtn.disabled = !(hasImage && hasQuestion);
|
276 |
-
}
|
277 |
-
|
278 |
-
async analyzeImage() {
|
279 |
-
if (!this.currentImage || !this.elements.questionInput.value.trim()) {
|
280 |
-
this.showNotification('Please provide an image and question', 'error');
|
281 |
-
return;
|
282 |
-
}
|
283 |
-
|
284 |
-
const question = this.elements.questionInput.value.trim();
|
285 |
-
this.setLoading(true);
|
286 |
-
|
287 |
-
try {
|
288 |
-
const startTime = Date.now();
|
289 |
-
const result = await this.queryMoondream(this.currentImage, question);
|
290 |
-
const endTime = Date.now();
|
291 |
-
const responseTime = ((endTime - startTime) / 1000).toFixed(1);
|
292 |
-
|
293 |
-
if (!result || !result.answer) {
|
294 |
-
throw new Error('Invalid response from API');
|
295 |
-
}
|
296 |
-
|
297 |
-
this.showResults(question, result.answer, result.request_id, responseTime);
|
298 |
-
this.showNotification('Analysis completed successfully', 'success');
|
299 |
-
|
300 |
-
} catch (error) {
|
301 |
-
console.error('Analysis error:', error);
|
302 |
-
this.showNotification(`Analysis failed: ${error.message}`, 'error');
|
303 |
-
} finally {
|
304 |
-
this.setLoading(false);
|
305 |
-
}
|
306 |
-
}
|
307 |
-
|
308 |
-
async queryMoondream(imageDataUrl, question) {
|
309 |
-
try {
|
310 |
-
const requestBody = {
|
311 |
-
image_url: imageDataUrl,
|
312 |
-
question: question,
|
313 |
-
stream: false
|
314 |
-
};
|
315 |
-
|
316 |
-
// Fixed the extra space in the URL
|
317 |
-
const response = await fetch('https://api.moondream.ai/v1/query', {
|
318 |
-
method: 'POST',
|
319 |
-
headers: {
|
320 |
-
'X-Moondream-Auth': this.apiKey,
|
321 |
-
'Content-Type': 'application/json',
|
322 |
-
},
|
323 |
-
body: JSON.stringify(requestBody)
|
324 |
-
});
|
325 |
-
|
326 |
-
if (!response.ok) {
|
327 |
-
const errorText = await response.text();
|
328 |
-
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
329 |
-
try {
|
330 |
-
const errorData = JSON.parse(errorText);
|
331 |
-
errorMessage = errorData.message || errorData.error || errorMessage;
|
332 |
-
} catch (e) {
|
333 |
-
errorMessage = errorText || errorMessage;
|
334 |
-
}
|
335 |
-
throw new Error(errorMessage);
|
336 |
-
}
|
337 |
-
|
338 |
-
const result = await response.json();
|
339 |
-
return {
|
340 |
-
answer: result.result || result.answer || 'No answer received',
|
341 |
-
request_id: result.request_id || result.id || `req_${Date.now()}`
|
342 |
-
};
|
343 |
-
|
344 |
-
} catch (error) {
|
345 |
-
throw new Error(`API request failed: ${error.message}`);
|
346 |
-
}
|
347 |
-
}
|
348 |
-
|
349 |
-
setLoading(isLoading) {
|
350 |
-
if (isLoading) {
|
351 |
-
this.elements.analyzeText.innerHTML = '<span class="loading-dots">Analyzing</span>';
|
352 |
-
this.elements.analyzeBtn.disabled = true;
|
353 |
-
} else {
|
354 |
-
this.elements.analyzeText.textContent = 'Analyze Image';
|
355 |
-
this.updateAnalyzeButton();
|
356 |
-
}
|
357 |
-
}
|
358 |
-
|
359 |
-
showResults(question, answer, requestId, responseTime) {
|
360 |
-
this.elements.questionDisplay.textContent = question;
|
361 |
-
this.elements.answerDisplay.textContent = answer;
|
362 |
-
this.elements.requestId.textContent = requestId;
|
363 |
-
this.elements.responseTime.textContent = `${responseTime}s`;
|
364 |
-
this.elements.resultsSection.classList.remove('hidden');
|
365 |
-
|
366 |
-
// Smooth scroll to results
|
367 |
-
this.elements.resultsSection.scrollIntoView({
|
368 |
-
behavior: 'smooth',
|
369 |
-
block: 'nearest'
|
370 |
-
});
|
371 |
-
}
|
372 |
-
|
373 |
-
showNotification(message, type = 'info') {
|
374 |
-
const notification = document.createElement('div');
|
375 |
-
const bgColor = type === 'error' ? 'bg-red-600' : type === 'success' ? 'bg-green-600' : 'bg-gray-900';
|
376 |
-
|
377 |
-
notification.className = `notification fixed top-4 right-4 ${bgColor} text-white px-4 py-3 rounded-lg shadow-lg z-50 text-sm font-medium`;
|
378 |
-
notification.textContent = message;
|
379 |
-
|
380 |
-
document.body.appendChild(notification);
|
381 |
-
|
382 |
-
setTimeout(() => {
|
383 |
-
notification.remove();
|
384 |
-
}, 4000);
|
385 |
-
}
|
386 |
-
}
|
387 |
-
|
388 |
-
// Initialize the app when DOM is loaded
|
389 |
-
document.addEventListener('DOMContentLoaded', () => {
|
390 |
-
new VisionApp();
|
391 |
-
});
|
392 |
-
</script>
|
393 |
-
</body>
|
394 |
-
</html>
|
|
|
1 |
+
Coming soon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|