Spaces:
Running

deepi8 commited on
Commit
3891e2c
Β·
verified Β·
1 Parent(s): e064732

Update index.html

Browse files
Files changed (1) hide show
  1. 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.9.0"></script>
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 an image to preview here">
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
- // πŸ‘‡ Use your Hugging Face absolute paths
75
- model = await tf.loadGraphModel("https://huggingface.co/spaces/deepi8/solar-webapp/resolve/main/model.json");
76
- const metadata = await fetch("https://huggingface.co/spaces/deepi8/solar-webapp/resolve/main/metadata.json").then(r => r.json());
 
 
 
77
  labels = metadata.labels;
78
- console.log("βœ… Model loaded successfully!");
79
- document.getElementById('loading').innerText = "Model ready βœ…";
80
- setTimeout(() => document.getElementById('loading').innerText = "", 2000);
81
- } catch (e) {
82
- console.error("Model load error:", e);
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... please wait.";
95
  return;
96
  }
97
 
@@ -102,14 +106,14 @@
102
  .div(255)
103
  .expandDims();
104
 
105
- const preds = await model.predict(tensor).data();
106
- const maxIdx = preds.indexOf(Math.max(...preds));
107
  const predictedClass = labels[maxIdx];
108
- const accuracy = (preds[maxIdx] * 100).toFixed(2);
109
 
110
  document.getElementById('loading').innerText = "";
111
  document.getElementById('result-box').innerHTML = `🟒 Predicted: <span style="color:#0078d7">${predictedClass}</span>`;
112
- document.getElementById('accuracy').innerHTML = `🎯 Accuracy: ${accuracy}%`;
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