Spaces:
Running
<!-- باقي الكود... -->
Browse files<!-- هام: أضف السكربت التالي هنا قرب إغلاق </body> -->
<script>
document.getElementById('identifyBtn').addEventListener('click', async function() {
const fileInputs = document.querySelectorAll('input[type="file"]');
let selectedFile = null;
fileInputs.forEach(input => {
if (input.files && input.files.length > 0) {
selectedFile = input.files[0];
}
});
if (!selectedFile) {
alert('يرجى رفع صورة أو التقاطها أولاً');
return;
}
const btn = this;
btn.disabled = true;
btn.innerHTML = '<i data-feather="loader" class="animate-spin mr-2 h-4 w-4"></i> جاري التعرف...';
feather.replace();
try {
const formData = new FormData();
formData.append('image', selectedFile);
const response = await fetch('https://api.plant.id/v2/identify', {
method: 'POST',
headers: {
'Api-Key': 'demo' // استبدل المفتاح هنا لمفتاحك الحقيقي عند الاستخدام
},
body: formData
});
if (!response.ok) throw new Error('فشل التعرف');
const data = await response.json();
if (data.suggestions && data.suggestions.length > 0) {
sessionStorage.setItem('plantData', JSON.stringify(data));
window.location.href = 'results.html';
} else {
alert('تعذر التعرف على النبات، حاول صورة أوضح.');
}
} catch (error) {
alert('حدث خطأ أثناء الاتصال: ' + error.message);
} finally {
btn.disabled = false;
btn.innerHTML = '<i data-feather="search" class="mr-2 h-4 w-4"></i> Identify Plant';
feather.replace();
}
});
</script>
</body>
</html>
ضيف دا هنا بحيث انه يشتغل
- index.html +91 -5
|
@@ -108,10 +108,10 @@
|
|
| 108 |
</label>
|
| 109 |
</div>
|
| 110 |
</div>
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
document.getElementById('identifyBtn').addEventListener('click', async function() {
|
| 116 |
const fileInputs = document.querySelectorAll('input[type="file"]');
|
| 117 |
let selectedFile = null;
|
|
@@ -397,7 +397,6 @@
|
|
| 397 |
|
| 398 |
// Initialize feather icons
|
| 399 |
feather.replace();
|
| 400 |
-
|
| 401 |
// Animation for upload card
|
| 402 |
document.addEventListener('DOMContentLoaded', function() {
|
| 403 |
const uploadCard = document.querySelector('.pulse-animation');
|
|
@@ -409,6 +408,93 @@
|
|
| 409 |
uploadCard.addEventListener('mouseleave', function() {
|
| 410 |
this.classList.add('pulse-animation');
|
| 411 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
});
|
| 413 |
</script>
|
| 414 |
</body>
|
|
|
|
| 108 |
</label>
|
| 109 |
</div>
|
| 110 |
</div>
|
| 111 |
+
<button id="identifyBtn" class="mt-6 bg-green-500 hover:bg-green-600 text-white font-medium py-3 px-8 rounded-full flex items-center">
|
| 112 |
+
<i data-feather="search" class="mr-2 h-4 w-4"></i> تعرف على النبات
|
| 113 |
+
</button>
|
| 114 |
+
<script>
|
| 115 |
document.getElementById('identifyBtn').addEventListener('click', async function() {
|
| 116 |
const fileInputs = document.querySelectorAll('input[type="file"]');
|
| 117 |
let selectedFile = null;
|
|
|
|
| 397 |
|
| 398 |
// Initialize feather icons
|
| 399 |
feather.replace();
|
|
|
|
| 400 |
// Animation for upload card
|
| 401 |
document.addEventListener('DOMContentLoaded', function() {
|
| 402 |
const uploadCard = document.querySelector('.pulse-animation');
|
|
|
|
| 408 |
uploadCard.addEventListener('mouseleave', function() {
|
| 409 |
this.classList.add('pulse-animation');
|
| 410 |
});
|
| 411 |
+
|
| 412 |
+
// Add Arabic translation for file input
|
| 413 |
+
document.querySelectorAll('input[type="file"]').forEach(input => {
|
| 414 |
+
input.addEventListener('change', function() {
|
| 415 |
+
const label = this.closest('label');
|
| 416 |
+
if (this.files.length > 0) {
|
| 417 |
+
label.querySelector('p:first-of-type').textContent = 'تم اختيار الصورة';
|
| 418 |
+
} else {
|
| 419 |
+
label.querySelector('p:first-of-type').textContent = 'رفع من المعرض';
|
| 420 |
+
}
|
| 421 |
+
});
|
| 422 |
+
});
|
| 423 |
+
});
|
| 424 |
+
|
| 425 |
+
// Arabic identification script
|
| 426 |
+
document.getElementById('identifyBtn').addEventListener('click', async function() {
|
| 427 |
+
const fileInputs = document.querySelectorAll('input[type="file"]');
|
| 428 |
+
let selectedFile = null;
|
| 429 |
+
|
| 430 |
+
fileInputs.forEach(input => {
|
| 431 |
+
if (input.files && input.files.length > 0) {
|
| 432 |
+
selectedFile = input.files[0];
|
| 433 |
+
}
|
| 434 |
+
});
|
| 435 |
+
|
| 436 |
+
if (!selectedFile) {
|
| 437 |
+
alert('يرجى رفع صورة أو التقاطها أولاً');
|
| 438 |
+
return;
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
const btn = this;
|
| 442 |
+
btn.disabled = true;
|
| 443 |
+
btn.innerHTML = '<i data-feather="loader" class="animate-spin mr-2 h-4 w-4"></i> جاري التعرف...';
|
| 444 |
+
feather.replace();
|
| 445 |
+
|
| 446 |
+
try {
|
| 447 |
+
const formData = new FormData();
|
| 448 |
+
formData.append('image', selectedFile);
|
| 449 |
+
|
| 450 |
+
// Store the file for results page
|
| 451 |
+
sessionStorage.setItem('uploadedImage', JSON.stringify({
|
| 452 |
+
name: selectedFile.name,
|
| 453 |
+
type: selectedFile.type,
|
| 454 |
+
lastModified: selectedFile.lastModified
|
| 455 |
+
}));
|
| 456 |
+
|
| 457 |
+
const response = await fetch('https://api.plant.id/v2/identify', {
|
| 458 |
+
method: 'POST',
|
| 459 |
+
headers: {
|
| 460 |
+
'Api-Key': 'demo',
|
| 461 |
+
'Content-Type': 'multipart/form-data'
|
| 462 |
+
},
|
| 463 |
+
body: formData
|
| 464 |
+
});
|
| 465 |
+
|
| 466 |
+
if (!response.ok) {
|
| 467 |
+
throw new Error('Identification failed');
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
const data = await response.json();
|
| 471 |
+
|
| 472 |
+
if (data.suggestions && data.suggestions.length > 0) {
|
| 473 |
+
const result = {
|
| 474 |
+
plantData: data,
|
| 475 |
+
uploadedImage: {
|
| 476 |
+
name: selectedFile.name,
|
| 477 |
+
type: selectedFile.type,
|
| 478 |
+
size: selectedFile.size,
|
| 479 |
+
lastModified: selectedFile.lastModified
|
| 480 |
+
}
|
| 481 |
+
};
|
| 482 |
+
sessionStorage.setItem('plantResult', JSON.stringify(result));
|
| 483 |
+
window.location.href = 'results.html';
|
| 484 |
+
} else {
|
| 485 |
+
throw new Error('No plant identified');
|
| 486 |
+
}
|
| 487 |
+
} catch (error) {
|
| 488 |
+
alert('خطأ في التعرف: ' + error.message);
|
| 489 |
+
} finally {
|
| 490 |
+
btn.disabled = false;
|
| 491 |
+
btn.innerHTML = '<i data-feather="search" class="mr-2 h-4 w-4"></i> تعرف على النبات';
|
| 492 |
+
feather.replace();
|
| 493 |
+
|
| 494 |
+
document.querySelectorAll('input[type="file"]').forEach(input => {
|
| 495 |
+
input.value = '';
|
| 496 |
+
});
|
| 497 |
+
}
|
| 498 |
});
|
| 499 |
</script>
|
| 500 |
</body>
|