Spaces:
Running
Running
<!DOCTYPE html> <html lang="tr"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Teachable Machine Görüntü Modeli</title> <style> /* Genel sayfa düzeni ve hizalama */ body { font-family: 'Inter', sans-serif; /* Inter fontunu kullan */ display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; /* Sayfanın tamamını kapla */ margin: 0; background-color: #e0f2f7; /* Açık mavi arka plan */ color: #2c3e50; /* Koyu gri metin rengi */ padding: 20px; /* Kenarlara boşluk ekle */ box-sizing: border-box; /* Padding'in genişliğe dahil olmasını sağla */ } /* Başlık stili */ h1 { color: #1a73e8; /* Google mavisi */ margin-bottom: 25px; font-size: 2.2em; text-align: center; border-bottom: 2px solid #1a73e8; padding-bottom: 10px; width: 90%; max-width: 600px; } /* Butonlar ve dosya yükleme alanı için kapsayıcı */ .controls-container { display: flex; flex-direction: column; align-items: center; gap: 15px; /* Butonlar ve input arasında boşluk */ margin-bottom: 25px; width: 90%; max-width: 400px; } /* Buton stili */ button { background-color: #4285f4; /* Google mavi butonu */ color: white; padding: 12px 25px; border: none; border-radius: 25px; /* Daha yuvarlak köşeler */ cursor: pointer; font-size: 1.1em; transition: background-color 0.3s ease, transform 0.2s ease; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Hafif gölge */ outline: none; /* Odaklandığında dış çizgiyi kaldır */ width: 100%; /* Kapsayıcıya göre genişlik */ max-width: 250px; /* Maksimum genişlik */ } button:hover { background-color: #357ae8; /* Hover'da daha koyu mavi */ transform: translateY(-2px); /* Hafif yukarı kaydırma efekti */ } button:active { transform: translateY(0); /* Tıklamada geri gelme efekti */ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); } /* Dosya yükleme input stili */ input[type="file"] { border: 2px dashed #b3e5fc; border-radius: 10px; padding: 15px; width: 100%; max-width: 300px; text-align: center; background-color: #f0f8ff; /* Açık mavi tonu */ cursor: pointer; color: #1a73e8; font-size: 1em; transition: border-color 0.3s ease; } input[type="file"]::-webkit-file-upload-button { visibility: hidden; } input[type="file"]::before { content: 'Görsel Yükle'; display: inline-block; background: linear-gradient(to bottom, #4285f4, #357ae8); border-radius: 20px; padding: 8px 16px; outline: none; white-space: nowrap; -webkit-user-select: none; cursor: pointer; font-weight: 700; font-size: 10pt; color: white; margin-right: 10px; } input[type="file"]:hover::before { border-color: #357ae8; } input[type="file"]:active::before { background: #357ae8; } /* Web kamerası/Görsel kapsayıcısı stili */ #media-container { border: 3px solid #b3e5fc; /* Açık mavi çerçeve */ border-radius: 15px; /* Yuvarlak köşeler */ overflow: hidden; /* İçeriğin taşmasını engelle */ margin-bottom: 25px; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.25); /* Daha belirgin gölge */ background-color: #ffffff; /* Beyaz arka plan */ display: flex; /* İçeriği ortalamak için flex kullan */ justify-content: center; align-items: center; width: 220px; /* Sabit genişlik */ height: 220px; /* Sabit yükseklik */ } /* Kanvas veya yüklenen görsel stili */ #media-container canvas, #media-container img { display: block; /* Kanvasın/görselin altında boşluk olmasını engeller */ border-radius: 12px; /* Yuvarlak köşeler */ max-width: 100%; /* Responsive olması için */ max-height: 100%; /* Responsive olması için */ object-fit: contain; /* Görselin kapsayıcıya sığmasını sağla */ } /* Etiket sonuçları kapsayıcısı stili */ #label-container { background-color: #ffffff; /* Beyaz arka plan */ padding: 20px; border-radius: 15px; /* Yuvarlak köşeler */ box-shadow: 0 8px 16px rgba(0, 0, 0, 0.25); /* Daha belirgin gölge */ width: 90%; max-width: 350px; /* Maksimum genişlik */ text-align: center; margin-top: 15px; /* Üstten boşluk */ } /* Her bir etiket satırı stili */ #label-container div { padding: 10px 0; border-bottom: 1px solid #e0e0e0; /* Açık gri ayırıcı çizgi */ font-size: 1.1em; color: #34495e; /* Koyu gri metin */ transition: background-color 0.2s ease; } /* Son etiketin alt çizgisini kaldır */ #label-container div:last-child { border-bottom: none; } /* Yükleniyor göstergesi */ .loading-spinner { border: 4px solid #f3f3f3; /* Light grey */ border-top: 4px solid #4285f4; /* Blue */ border-radius: 50%; width: 30px; height: 30px; animation: spin 1s linear infinite; display: none; /* Varsayılan olarak gizli */ margin-top: 10px; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } /* Mobil uyumluluk için medya sorguları */ @media (max-width: 600px) { h1 { font-size: 1.8em; width: 95%; } button { padding: 10px 20px; font-size: 1em; } #media-container { width: 180px; height: 180px; } #label-container { padding: 15px; max-width: 95%; } #label-container div { font-size: 1em; } } </style> </head> <body> <h1>Teachable Machine Görüntü Modeli</h1> <div class="controls-container"> <button type="button" onclick="startWebcam()">Kamerayı Başlat</button> <input type="file" id="imageUpload" accept="image/*"> <button type="button" onclick="processUploadedImage()">Görseli Analiz Et</button> </div> <div id="media-container"> <!-- Kamera görüntüsü veya yüklenen görsel buraya gelecek --> </div> <!-- Yükleniyor göstergesi media-container dışına taşındı --> <div class="loading-spinner" id="loadingSpinner"></div> <div id="label-container"></div> <!-- TensorFlow.js ve Teachable Machine kütüphaneleri --> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest/dist/tf.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@teachablemachine/image@latest/dist/teachablemachine-image.min.js"></script> <script type="text/javascript"> // Teachable Machine modelinizin URL'si // Kendi modelinizi kullanıyorsanız bu URL'yi değiştirmeniz gerekmektedir. const URL = "https://teachablemachine.withgoogle.com/models/SMwI3_lD/"; let model, webcam, labelContainer, maxPredictions; let isWebcamActive = false; // Kameranın aktif olup olmadığını takip eder let loopId; // requestAnimationFrame döngüsünün ID'si // Sayfa yüklendiğinde modeli önceden yükle window.onload = async () => { await loadModel(); }; // Modeli yükleme fonksiyonu async function loadModel() { const modelURL = URL + "model.json"; const metadataURL = URL + "metadata.json"; try { model = await tmImage.load(modelURL, metadataURL); maxPredictions = model.getTotalClasses(); labelContainer = document.getElementById("label-container"); // Etiketler için div'leri oluştur for (let i = 0; i < maxPredictions; i++) { labelContainer.appendChild(document.createElement("div")); } console.log("Model başarıyla yüklendi."); } catch (error) { console.error("Model yüklenirken hata oluştu:", error); if (labelContainer) { labelContainer.innerHTML = '<div>Hata: Model yüklenemedi. URL\'yi kontrol edin.</div>'; } } } // Kamerayı başlatma fonksiyonu async function startWebcam() { // Eğer kamera zaten aktifse veya model yüklenmediyse bir şey yapma if (isWebcamActive || !model) return; // Önceki görüntüyü temizle ve yükleme göstergesini gizle document.getElementById("media-container").innerHTML = ''; document.getElementById("loadingSpinner").style.display = 'none'; clearLabelContainer(); try { const flip = true; // Web kamerasını yatayda çevir webcam = new tmImage.Webcam(200, 200, flip); // Genişlik, yükseklik, çevirme ayarı await webcam.setup(); // Web kamerasına erişim izni iste await webcam.play(); // Web kamerasını başlat document.getElementById("media-container").appendChild(webcam.canvas); isWebcamActive = true; loopId = window.requestAnimationFrame(loop); // Sürekli tahmin için animasyon döngüsünü başlat console.log("Kamera başlatıldı."); } catch (error) { console.error("Kamera başlatılırken hata oluştu:", error); isWebcamActive = false; if (labelContainer) { labelContainer.innerHTML = '<div>Hata: Kameraya erişim sağlanamadı. Lütfen izin verin.</div>'; } } } // Kamera döngüsü async function loop() { if (webcam && isWebcamActive) { webcam.update(); // Web kamerası çerçevesini güncelle await predict(webcam.canvas); // Tahmin yap loopId = window.requestAnimationFrame(loop); // Bir sonraki kare için tekrar çağır } } // Yüklenen görseli işleme fonksiyonu async function processUploadedImage() { // Eğer kamera aktifse durdur stopWebcam(); const imageUpload = document.getElementById("imageUpload"); const file = imageUpload.files[0]; if (!file) { // Özel bir modal veya mesaj kutusu kullanın, alert() kullanmayın console.warn("Lütfen bir görsel dosyası seçin."); return; } if (!model) { // Özel bir modal veya mesaj kutusu kullanın, alert() kullanmayın console.warn("Model henüz yüklenmedi. Lütfen bekleyin veya sayfayı yenileyin."); return; } // Önceki görüntüyü temizle ve yükleme göstergesini göster document.getElementById("media-container").innerHTML = ''; const loadingSpinner = document.getElementById("loadingSpinner"); // Spinner'ı göstermeden önce elementin var olduğundan emin ol if (loadingSpinner) { loadingSpinner.style.display = 'block'; // Yükleniyor spinner'ını göster } clearLabelContainer(); const reader = new FileReader(); reader.onload = async (e) => { const img = new Image(); img.onload = async () => { document.getElementById("media-container").innerHTML = ''; // Spinner'ı kaldır document.getElementById("media-container").appendChild(img); await predict(img); // Görsel üzerinde tahmin yap if (loadingSpinner) { loadingSpinner.style.display = 'none'; // Yükleniyor spinner'ını gizle } }; img.onerror = () => { console.error("Görsel yüklenirken hata oluştu."); if (loadingSpinner) { loadingSpinner.style.display = 'none'; } if (labelContainer) { labelContainer.innerHTML = '<div>Hata: Görsel yüklenemedi.</div>'; } }; img.src = e.target.result; }; reader.readAsDataURL(file); // Dosyayı base64 string olarak oku } // Tahmin yapma fonksiyonu (hem kanvas hem de görsel için) async function predict(inputElement) { if (model && inputElement) { const prediction = await model.predict(inputElement); // Her sınıf için tahmin sonuçlarını göster for (let i = 0; i < maxPredictions; i++) { const classPrediction = prediction[i].className + ": " + prediction[i].probability.toFixed(2); // Sınıf adı ve olasılık if (labelContainer && labelContainer.childNodes[i]) { labelContainer.childNodes[i].innerHTML = classPrediction; } } } } // Kamerayı durdurma fonksiyonu function stopWebcam() { if (isWebcamActive && webcam) { webcam.stop(); window.cancelAnimationFrame(loopId); isWebcamActive = false; console.log("Kamera durduruldu."); } } // Etiket kapsayıcısını temizleme fonksiyonu function clearLabelContainer() { if (labelContainer) { for (let i = 0; i < maxPredictions; i++) { if (labelContainer.childNodes[i]) { labelContainer.childNodes[i].innerHTML = ''; } } } } </script> </body> </html> - Initial Deployment
Browse files- README.md +7 -5
- index.html +333 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: teachable-machine
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,333 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="tr">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Teachable Machine Görüntü Modeli</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 9 |
+
<style>
|
| 10 |
+
/* Custom styles that can't be done with Tailwind */
|
| 11 |
+
input[type="file"]::-webkit-file-upload-button {
|
| 12 |
+
visibility: hidden;
|
| 13 |
+
}
|
| 14 |
+
input[type="file"]::before {
|
| 15 |
+
content: 'Görsel Yükle';
|
| 16 |
+
display: inline-block;
|
| 17 |
+
background: linear-gradient(to bottom, #3b82f6, #2563eb);
|
| 18 |
+
border-radius: 9999px;
|
| 19 |
+
padding: 0.5rem 1rem;
|
| 20 |
+
outline: none;
|
| 21 |
+
white-space: nowrap;
|
| 22 |
+
-webkit-user-select: none;
|
| 23 |
+
cursor: pointer;
|
| 24 |
+
font-weight: 600;
|
| 25 |
+
font-size: 0.875rem;
|
| 26 |
+
color: white;
|
| 27 |
+
margin-right: 10px;
|
| 28 |
+
}
|
| 29 |
+
input[type="file"]:hover::before {
|
| 30 |
+
background: linear-gradient(to bottom, #2563eb, #1d4ed8);
|
| 31 |
+
}
|
| 32 |
+
input[type="file"]:active::before {
|
| 33 |
+
background: #1d4ed8;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
@keyframes spin {
|
| 37 |
+
0% { transform: rotate(0deg); }
|
| 38 |
+
100% { transform: rotate(360deg); }
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.loading-spinner {
|
| 42 |
+
border: 4px solid #f3f4f6;
|
| 43 |
+
border-top: 4px solid #3b82f6;
|
| 44 |
+
border-radius: 50%;
|
| 45 |
+
width: 30px;
|
| 46 |
+
height: 30px;
|
| 47 |
+
animation: spin 1s linear infinite;
|
| 48 |
+
}
|
| 49 |
+
</style>
|
| 50 |
+
</head>
|
| 51 |
+
<body class="font-sans bg-blue-50 min-h-screen flex flex-col items-center justify-center p-5 text-gray-800">
|
| 52 |
+
<div class="w-full max-w-3xl mx-auto text-center">
|
| 53 |
+
<!-- Header Section -->
|
| 54 |
+
<div class="mb-8">
|
| 55 |
+
<h1 class="text-3xl md:text-4xl font-bold text-blue-600 mb-4">Teachable Machine Görüntü Modeli</h1>
|
| 56 |
+
<p class="text-gray-600 max-w-2xl mx-auto">
|
| 57 |
+
Yapay zeka modelinizle görüntüleri analiz edin. Kameranızı kullanabilir veya bir görsel yükleyebilirsiniz.
|
| 58 |
+
</p>
|
| 59 |
+
</div>
|
| 60 |
+
|
| 61 |
+
<!-- Controls Section -->
|
| 62 |
+
<div class="bg-white rounded-xl shadow-lg p-6 mb-8 w-full max-w-md mx-auto">
|
| 63 |
+
<div class="space-y-4">
|
| 64 |
+
<button
|
| 65 |
+
onclick="startWebcam()"
|
| 66 |
+
class="w-full bg-blue-500 hover:bg-blue-600 text-white font-medium py-3 px-6 rounded-full transition-all duration-200 transform hover:-translate-y-1 shadow-md"
|
| 67 |
+
>
|
| 68 |
+
<div class="flex items-center justify-center space-x-2">
|
| 69 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
| 70 |
+
<path d="M2 6a2 2 0 012-2h6a2 2 0 012 2v8a2 2 0 01-2 2H4a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v8a2 2 0 01-2 2h-2a2 2 0 01-2-2V6z" />
|
| 71 |
+
</svg>
|
| 72 |
+
<span>Kamerayı Başlat</span>
|
| 73 |
+
</div>
|
| 74 |
+
</button>
|
| 75 |
+
|
| 76 |
+
<div class="relative">
|
| 77 |
+
<input
|
| 78 |
+
type="file"
|
| 79 |
+
id="imageUpload"
|
| 80 |
+
accept="image/*"
|
| 81 |
+
class="w-full border-2 border-dashed border-blue-200 rounded-lg p-4 bg-blue-50 text-blue-500 font-medium cursor-pointer focus:outline-none focus:ring-2 focus:ring-blue-300 focus:border-transparent"
|
| 82 |
+
>
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<button
|
| 86 |
+
onclick="processUploadedImage()"
|
| 87 |
+
class="w-full bg-green-500 hover:bg-green-600 text-white font-medium py-3 px-6 rounded-full transition-all duration-200 transform hover:-translate-y-1 shadow-md"
|
| 88 |
+
>
|
| 89 |
+
<div class="flex items-center justify-center space-x-2">
|
| 90 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
| 91 |
+
<path fill-rule="evenodd" d="M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm3.293-7.707a1 1 0 011.414 0L9 10.586V3a1 1 0 112 0v7.586l1.293-1.293a1 1 0 111.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z" clip-rule="evenodd" />
|
| 92 |
+
</svg>
|
| 93 |
+
<span>Görseli Analiz Et</span>
|
| 94 |
+
</div>
|
| 95 |
+
</button>
|
| 96 |
+
</div>
|
| 97 |
+
</div>
|
| 98 |
+
|
| 99 |
+
<!-- Media Display Section -->
|
| 100 |
+
<div class="flex flex-col md:flex-row items-center justify-center gap-8 w-full mb-8">
|
| 101 |
+
<div id="media-container" class="bg-white border-4 border-blue-200 rounded-xl overflow-hidden shadow-xl w-56 h-56 flex items-center justify-center">
|
| 102 |
+
<div class="text-gray-400 text-center p-4">
|
| 103 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 mx-auto mb-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 104 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
| 105 |
+
</svg>
|
| 106 |
+
<p>Kamera veya görsel burada görünecek</p>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
<div id="label-container" class="bg-white rounded-xl shadow-xl p-6 w-full max-w-md">
|
| 111 |
+
<h3 class="text-xl font-semibold text-gray-700 mb-4">Analiz Sonuçları</h3>
|
| 112 |
+
<div class="space-y-3 text-gray-600">
|
| 113 |
+
<div class="py-2 border-b border-gray-100">Model yükleniyor...</div>
|
| 114 |
+
</div>
|
| 115 |
+
</div>
|
| 116 |
+
</div>
|
| 117 |
+
|
| 118 |
+
<!-- Loading Spinner -->
|
| 119 |
+
<div id="loadingSpinner" class="loading-spinner hidden my-4"></div>
|
| 120 |
+
|
| 121 |
+
<!-- Info Box -->
|
| 122 |
+
<div class="bg-blue-100 border-l-4 border-blue-500 text-blue-700 p-4 rounded-lg max-w-2xl mx-auto mt-6" role="alert">
|
| 123 |
+
<div class="flex items-center">
|
| 124 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 125 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
| 126 |
+
</svg>
|
| 127 |
+
<p class="font-medium">İpucu:</p>
|
| 128 |
+
</div>
|
| 129 |
+
<p class="mt-2">Kamerayı başlatın veya bir görsel yükleyin. Model görüntüyü analiz edecek ve sonuçları gösterecektir.</p>
|
| 130 |
+
</div>
|
| 131 |
+
</div>
|
| 132 |
+
|
| 133 |
+
<!-- TensorFlow.js and Teachable Machine libraries -->
|
| 134 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest/dist/tf.min.js"></script>
|
| 135 |
+
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/image@latest/dist/teachablemachine-image.min.js"></script>
|
| 136 |
+
|
| 137 |
+
<script type="text/javascript">
|
| 138 |
+
// Teachable Machine modelinizin URL'si
|
| 139 |
+
// Kendi modelinizi kullanıyorsanız bu URL'yi değiştirmeniz gerekmektedir.
|
| 140 |
+
const URL = "https://teachablemachine.withgoogle.com/models/SMwI3_lD/";
|
| 141 |
+
|
| 142 |
+
let model, webcam, labelContainer, maxPredictions;
|
| 143 |
+
let isWebcamActive = false; // Kameranın aktif olup olmadığını takip eder
|
| 144 |
+
let loopId; // requestAnimationFrame döngüsünün ID'si
|
| 145 |
+
|
| 146 |
+
// Sayfa yüklendiğinde modeli önceden yükle
|
| 147 |
+
window.onload = async () => {
|
| 148 |
+
await loadModel();
|
| 149 |
+
};
|
| 150 |
+
|
| 151 |
+
// Modeli yükleme fonksiyonu
|
| 152 |
+
async function loadModel() {
|
| 153 |
+
const modelURL = URL + "model.json";
|
| 154 |
+
const metadataURL = URL + "metadata.json";
|
| 155 |
+
try {
|
| 156 |
+
model = await tmImage.load(modelURL, metadataURL);
|
| 157 |
+
maxPredictions = model.getTotalClasses();
|
| 158 |
+
labelContainer = document.getElementById("label-container");
|
| 159 |
+
|
| 160 |
+
// Clear existing content
|
| 161 |
+
labelContainer.querySelector('div.space-y-3').innerHTML = '';
|
| 162 |
+
|
| 163 |
+
// Create divs for each prediction class
|
| 164 |
+
for (let i = 0; i < maxPredictions; i++) {
|
| 165 |
+
const div = document.createElement('div');
|
| 166 |
+
div.className = 'py-2 border-b border-gray-100';
|
| 167 |
+
labelContainer.querySelector('div.space-y-3').appendChild(div);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
console.log("Model başarıyla yüklendi.");
|
| 171 |
+
} catch (error) {
|
| 172 |
+
console.error("Model yüklenirken hata oluştu:", error);
|
| 173 |
+
if (labelContainer) {
|
| 174 |
+
labelContainer.querySelector('div.space-y-3').innerHTML = '<div class="text-red-500">Hata: Model yüklenemedi. URL\'yi kontrol edin.</div>';
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
// Kamerayı başlatma fonksiyonu
|
| 180 |
+
async function startWebcam() {
|
| 181 |
+
// Eğer kamera zaten aktifse veya model yüklenmediyse bir şey yapma
|
| 182 |
+
if (isWebcamActive || !model) return;
|
| 183 |
+
|
| 184 |
+
// Önceki görüntüyü temizle ve yükleme göstergesini gizle
|
| 185 |
+
document.getElementById("media-container").innerHTML = '';
|
| 186 |
+
document.getElementById("loadingSpinner").classList.add('hidden');
|
| 187 |
+
clearLabelContainer();
|
| 188 |
+
|
| 189 |
+
try {
|
| 190 |
+
const flip = true; // Web kamerasını yatayda çevir
|
| 191 |
+
webcam = new tmImage.Webcam(224, 224, flip); // Genişlik, yükseklik, çevirme ayarı
|
| 192 |
+
await webcam.setup(); // Web kamerasına erişim izni iste
|
| 193 |
+
await webcam.play(); // Web kamerasını başlat
|
| 194 |
+
|
| 195 |
+
document.getElementById("media-container").appendChild(webcam.canvas);
|
| 196 |
+
isWebcamActive = true;
|
| 197 |
+
loopId = window.requestAnimationFrame(loop); // Sürekli tahmin için animasyon döngüsünü başlat
|
| 198 |
+
console.log("Kamera başlatıldı.");
|
| 199 |
+
} catch (error) {
|
| 200 |
+
console.error("Kamera başlatılırken hata oluştu:", error);
|
| 201 |
+
isWebcamActive = false;
|
| 202 |
+
if (labelContainer) {
|
| 203 |
+
labelContainer.querySelector('div.space-y-3').innerHTML = '<div class="text-red-500">Hata: Kameraya erişim sağlanamadı. Lütfen izin verin.</div>';
|
| 204 |
+
}
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
// Kamera döngüsü
|
| 209 |
+
async function loop() {
|
| 210 |
+
if (webcam && isWebcamActive) {
|
| 211 |
+
webcam.update(); // Web kamerası çerçevesini güncelle
|
| 212 |
+
await predict(webcam.canvas); // Tahmin yap
|
| 213 |
+
loopId = window.requestAnimationFrame(loop); // Bir sonraki kare için tekrar çağır
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
// Yüklenen görseli işleme fonksiyonu
|
| 218 |
+
async function processUploadedImage() {
|
| 219 |
+
// Eğer kamera aktifse durdur
|
| 220 |
+
stopWebcam();
|
| 221 |
+
|
| 222 |
+
const imageUpload = document.getElementById("imageUpload");
|
| 223 |
+
const file = imageUpload.files[0];
|
| 224 |
+
|
| 225 |
+
if (!file) {
|
| 226 |
+
showToast("Lütfen bir görsel dosyası seçin.", "warning");
|
| 227 |
+
return;
|
| 228 |
+
}
|
| 229 |
+
if (!model) {
|
| 230 |
+
showToast("Model henüz yüklenmedi. Lütfen bekleyin.", "error");
|
| 231 |
+
return;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
// Önceki görüntüyü temizle ve yükleme göstergesini göster
|
| 235 |
+
document.getElementById("media-container").innerHTML = '';
|
| 236 |
+
document.getElementById("loadingSpinner").classList.remove('hidden');
|
| 237 |
+
clearLabelContainer();
|
| 238 |
+
|
| 239 |
+
const reader = new FileReader();
|
| 240 |
+
reader.onload = async (e) => {
|
| 241 |
+
const img = new Image();
|
| 242 |
+
img.onload = async () => {
|
| 243 |
+
document.getElementById("media-container").innerHTML = '';
|
| 244 |
+
document.getElementById("media-container").appendChild(img);
|
| 245 |
+
await predict(img); // Görsel üzerinde tahmin yap
|
| 246 |
+
document.getElementById("loadingSpinner").classList.add('hidden');
|
| 247 |
+
};
|
| 248 |
+
img.onerror = () => {
|
| 249 |
+
console.error("Görsel yüklenirken hata oluştu.");
|
| 250 |
+
document.getElementById("loadingSpinner").classList.add('hidden');
|
| 251 |
+
if (labelContainer) {
|
| 252 |
+
labelContainer.querySelector('div.space-y-3').innerHTML = '<div class="text-red-500">Hata: Görsel yüklenemedi.</div>';
|
| 253 |
+
}
|
| 254 |
+
};
|
| 255 |
+
img.src = e.target.result;
|
| 256 |
+
};
|
| 257 |
+
reader.readAsDataURL(file); // Dosyayı base64 string olarak oku
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
// Tahmin yapma fonksiyonu (hem kanvas hem de görsel için)
|
| 261 |
+
async function predict(inputElement) {
|
| 262 |
+
if (model && inputElement) {
|
| 263 |
+
const prediction = await model.predict(inputElement);
|
| 264 |
+
|
| 265 |
+
// Her sınıf için tahmin sonuçlarını göster
|
| 266 |
+
const resultDivs = labelContainer.querySelectorAll('div.space-y-3 > div');
|
| 267 |
+
for (let i = 0; i < maxPredictions; i++) {
|
| 268 |
+
const probability = prediction[i].probability.toFixed(2);
|
| 269 |
+
const percentage = Math.round(probability * 100);
|
| 270 |
+
|
| 271 |
+
// Create a progress bar
|
| 272 |
+
const progressBar = `
|
| 273 |
+
<div class="w-full bg-gray-200 rounded-full h-2.5 mt-1">
|
| 274 |
+
<div class="bg-blue-600 h-2.5 rounded-full" style="width: ${percentage}%"></div>
|
| 275 |
+
</div>
|
| 276 |
+
`;
|
| 277 |
+
|
| 278 |
+
resultDivs[i].innerHTML = `
|
| 279 |
+
<div class="flex justify-between items-center">
|
| 280 |
+
<span class="font-medium">${prediction[i].className}:</span>
|
| 281 |
+
<span class="font-semibold">${percentage}%</span>
|
| 282 |
+
</div>
|
| 283 |
+
${progressBar}
|
| 284 |
+
`;
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
// Kamerayı durdurma fonksiyonu
|
| 290 |
+
function stopWebcam() {
|
| 291 |
+
if (isWebcamActive && webcam) {
|
| 292 |
+
webcam.stop();
|
| 293 |
+
window.cancelAnimationFrame(loopId);
|
| 294 |
+
isWebcamActive = false;
|
| 295 |
+
console.log("Kamera durduruldu.");
|
| 296 |
+
}
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
// Etiket kapsayıcısını temizleme fonksiyonu
|
| 300 |
+
function clearLabelContainer() {
|
| 301 |
+
if (labelContainer) {
|
| 302 |
+
const resultDivs = labelContainer.querySelectorAll('div.space-y-3 > div');
|
| 303 |
+
resultDivs.forEach(div => {
|
| 304 |
+
div.innerHTML = '';
|
| 305 |
+
});
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
// Toast mesajı gösterme fonksiyonu
|
| 310 |
+
function showToast(message, type = 'info') {
|
| 311 |
+
const colors = {
|
| 312 |
+
info: 'bg-blue-500',
|
| 313 |
+
warning: 'bg-yellow-500',
|
| 314 |
+
error: 'bg-red-500',
|
| 315 |
+
success: 'bg-green-500'
|
| 316 |
+
};
|
| 317 |
+
|
| 318 |
+
const toast = document.createElement('div');
|
| 319 |
+
toast.className = `fixed bottom-4 right-4 text-white px-4 py-2 rounded-lg shadow-lg ${colors[type]} animate-fade-in`;
|
| 320 |
+
toast.textContent = message;
|
| 321 |
+
document.body.appendChild(toast);
|
| 322 |
+
|
| 323 |
+
setTimeout(() => {
|
| 324 |
+
toast.classList.remove('animate-fade-in');
|
| 325 |
+
toast.classList.add('animate-fade-out');
|
| 326 |
+
setTimeout(() => {
|
| 327 |
+
toast.remove();
|
| 328 |
+
}, 300);
|
| 329 |
+
}, 3000);
|
| 330 |
+
}
|
| 331 |
+
</script>
|
| 332 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=yusra21/teachable-machine" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 333 |
+
</html>
|