Spaces:
Running
Running
Update index.html
Browse files- index.html +21 -17
index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8">
|
| 5 |
<title>π Solar Panel Condition Classifier</title>
|
| 6 |
-
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.
|
| 7 |
<style>
|
| 8 |
body {
|
| 9 |
font-family: 'Segoe UI', Arial;
|
|
@@ -61,8 +61,8 @@
|
|
| 61 |
<p>Upload an image to detect if the solar panel is <b>Clean, Dusty, Bird-drop, Electrical Damage, Physical Damage, or Snow-Covered.</b></p>
|
| 62 |
|
| 63 |
<input type="file" id="fileInput" accept="image/*"><br>
|
| 64 |
-
<img id="preview" alt="Upload
|
| 65 |
-
<div id="loading"></div>
|
| 66 |
<div id="result-box"></div>
|
| 67 |
<div id="accuracy"></div>
|
| 68 |
|
|
@@ -71,27 +71,31 @@
|
|
| 71 |
|
| 72 |
async function loadModel() {
|
| 73 |
try {
|
| 74 |
-
//
|
| 75 |
-
|
| 76 |
-
const
|
|
|
|
|
|
|
|
|
|
| 77 |
labels = metadata.labels;
|
| 78 |
-
|
| 79 |
-
document.getElementById('loading').innerText = "
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
document.getElementById('loading').innerText = "β Model failed to load.";
|
| 84 |
}
|
| 85 |
}
|
| 86 |
|
| 87 |
fileInput.onchange = async (e) => {
|
| 88 |
const file = e.target.files[0];
|
|
|
|
|
|
|
| 89 |
const img = document.getElementById('preview');
|
| 90 |
img.src = URL.createObjectURL(file);
|
| 91 |
|
| 92 |
img.onload = async () => {
|
| 93 |
if (!model) {
|
| 94 |
-
document.getElementById('loading').innerText = "β³ Model loading...
|
| 95 |
return;
|
| 96 |
}
|
| 97 |
|
|
@@ -102,14 +106,14 @@
|
|
| 102 |
.div(255)
|
| 103 |
.expandDims();
|
| 104 |
|
| 105 |
-
const
|
| 106 |
-
const maxIdx =
|
| 107 |
const predictedClass = labels[maxIdx];
|
| 108 |
-
const accuracy = (
|
| 109 |
|
| 110 |
document.getElementById('loading').innerText = "";
|
| 111 |
document.getElementById('result-box').innerHTML = `π’ Predicted: <span style="color:#0078d7">${predictedClass}</span>`;
|
| 112 |
-
document.getElementById('accuracy').innerHTML = `π―
|
| 113 |
};
|
| 114 |
};
|
| 115 |
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8">
|
| 5 |
<title>π Solar Panel Condition Classifier</title>
|
| 6 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.21.0"></script>
|
| 7 |
<style>
|
| 8 |
body {
|
| 9 |
font-family: 'Segoe UI', Arial;
|
|
|
|
| 61 |
<p>Upload an image to detect if the solar panel is <b>Clean, Dusty, Bird-drop, Electrical Damage, Physical Damage, or Snow-Covered.</b></p>
|
| 62 |
|
| 63 |
<input type="file" id="fileInput" accept="image/*"><br>
|
| 64 |
+
<img id="preview" alt="Upload image to test" />
|
| 65 |
+
<div id="loading">β³ Loading model, please wait...</div>
|
| 66 |
<div id="result-box"></div>
|
| 67 |
<div id="accuracy"></div>
|
| 68 |
|
|
|
|
| 71 |
|
| 72 |
async function loadModel() {
|
| 73 |
try {
|
| 74 |
+
// π§ Model file URLs (your Hugging Face space path)
|
| 75 |
+
const modelURL = "https://huggingface.co/spaces/deepi8/solar-webapp/resolve/main/model.json";
|
| 76 |
+
const metadataURL = "https://huggingface.co/spaces/deepi8/solar-webapp/resolve/main/metadata.json";
|
| 77 |
+
|
| 78 |
+
model = await tf.loadGraphModel(modelURL);
|
| 79 |
+
const metadata = await fetch(metadataURL).then(r => r.json());
|
| 80 |
labels = metadata.labels;
|
| 81 |
+
document.getElementById('loading').innerText = "β
Model loaded successfully!";
|
| 82 |
+
setTimeout(() => document.getElementById('loading').innerText = "", 1500);
|
| 83 |
+
} catch (error) {
|
| 84 |
+
console.error(error);
|
| 85 |
+
document.getElementById('loading').innerText = "β Model failed to load. Check file paths.";
|
|
|
|
| 86 |
}
|
| 87 |
}
|
| 88 |
|
| 89 |
fileInput.onchange = async (e) => {
|
| 90 |
const file = e.target.files[0];
|
| 91 |
+
if (!file) return;
|
| 92 |
+
|
| 93 |
const img = document.getElementById('preview');
|
| 94 |
img.src = URL.createObjectURL(file);
|
| 95 |
|
| 96 |
img.onload = async () => {
|
| 97 |
if (!model) {
|
| 98 |
+
document.getElementById('loading').innerText = "β³ Model still loading...";
|
| 99 |
return;
|
| 100 |
}
|
| 101 |
|
|
|
|
| 106 |
.div(255)
|
| 107 |
.expandDims();
|
| 108 |
|
| 109 |
+
const prediction = await model.predict(tensor).data();
|
| 110 |
+
const maxIdx = prediction.indexOf(Math.max(...prediction));
|
| 111 |
const predictedClass = labels[maxIdx];
|
| 112 |
+
const accuracy = (prediction[maxIdx] * 100).toFixed(2);
|
| 113 |
|
| 114 |
document.getElementById('loading').innerText = "";
|
| 115 |
document.getElementById('result-box').innerHTML = `π’ Predicted: <span style="color:#0078d7">${predictedClass}</span>`;
|
| 116 |
+
document.getElementById('accuracy').innerHTML = `π― Confidence: ${accuracy}%`;
|
| 117 |
};
|
| 118 |
};
|
| 119 |
|