Spaces:
Running
Running
Download index.html from deepi8/solar-webapp: direct link, hf CLI and curl.
- Browser
- Download file 3.69 kB
-
https://huggingface.co/spaces/deepi8/solar-webapp/resolve/main/index.html
- Command line
-
hf download hf://spaces/deepi8/solar-webapp/index.html
-
curl -L -o index.html https://huggingface.co/spaces/deepi8/solar-webapp/resolve/main/index.html
3.69 kB
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>π Solar Panel Condition Classifier</title> | |
| <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.21.0"></script> | |
| <style> | |
| body { | |
| font-family: 'Segoe UI', Arial; | |
| text-align: center; | |
| background: linear-gradient(180deg, #e8f3ff, #ffffff); | |
| padding: 30px; | |
| } | |
| h1 { | |
| color: #0078d7; | |
| font-size: 28px; | |
| margin-bottom: 10px; | |
| } | |
| p { | |
| font-size: 16px; | |
| color: #333; | |
| margin-bottom: 25px; | |
| } | |
| input { | |
| margin: 15px; | |
| padding: 10px 20px; | |
| border-radius: 8px; | |
| background-color: #0078d7; | |
| color: white; | |
| border: none; | |
| cursor: pointer; | |
| font-size: 16px; | |
| } | |
| img { | |
| width: 350px; | |
| border-radius: 12px; | |
| margin-top: 10px; | |
| box-shadow: 0px 0px 10px rgba(0,0,0,0.2); | |
| } | |
| #result-box { | |
| margin-top: 20px; | |
| font-size: 22px; | |
| font-weight: bold; | |
| color: #222; | |
| } | |
| #accuracy { | |
| font-size: 18px; | |
| color: #0078d7; | |
| margin-top: 8px; | |
| } | |
| #loading { | |
| color: #ff6600; | |
| font-size: 18px; | |
| font-weight: bold; | |
| margin-top: 10px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>π Solar Panel Condition Classifier</h1> | |
| <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> | |
| <input type="file" id="fileInput" accept="image/*"><br> | |
| <img id="preview" alt="Upload image to test" /> | |
| <div id="loading">β³ Loading model, please wait...</div> | |
| <div id="result-box"></div> | |
| <div id="accuracy"></div> | |
| <script> | |
| let model, labels; | |
| async function loadModel() { | |
| try { | |
| // π§ Model file URLs (your Hugging Face space path) | |
| const modelURL = "https://huggingface.co/spaces/deepi8/solar-webapp/resolve/main/model.json"; | |
| const metadataURL = "https://huggingface.co/spaces/deepi8/solar-webapp/resolve/main/metadata.json"; | |
| model = await tf.loadGraphModel(modelURL); | |
| const metadata = await fetch(metadataURL).then(r => r.json()); | |
| labels = metadata.labels; | |
| document.getElementById('loading').innerText = "β Model loaded successfully!"; | |
| setTimeout(() => document.getElementById('loading').innerText = "", 1500); | |
| } catch (error) { | |
| console.error(error); | |
| document.getElementById('loading').innerText = "β Model failed to load. Check file paths."; | |
| } | |
| } | |
| fileInput.onchange = async (e) => { | |
| const file = e.target.files[0]; | |
| if (!file) return; | |
| const img = document.getElementById('preview'); | |
| img.src = URL.createObjectURL(file); | |
| img.onload = async () => { | |
| if (!model) { | |
| document.getElementById('loading').innerText = "β³ Model still loading..."; | |
| return; | |
| } | |
| document.getElementById('loading').innerText = "π Analyzing image..."; | |
| const tensor = tf.browser.fromPixels(img) | |
| .resizeNearestNeighbor([224, 224]) | |
| .toFloat() | |
| .div(255) | |
| .expandDims(); | |
| const prediction = await model.predict(tensor).data(); | |
| const maxIdx = prediction.indexOf(Math.max(...prediction)); | |
| const predictedClass = labels[maxIdx]; | |
| const accuracy = (prediction[maxIdx] * 100).toFixed(2); | |
| document.getElementById('loading').innerText = ""; | |
| document.getElementById('result-box').innerHTML = `π’ Predicted: <span style="color:#0078d7">${predictedClass}</span>`; | |
| document.getElementById('accuracy').innerHTML = `π― Confidence: ${accuracy}%`; | |
| }; | |
| }; | |
| loadModel(); | |
| </script> | |
| </body> | |
| </html> | |