Spaces:
No application file
No application file
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,123 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import numpy as np
|
| 3 |
-
from PIL import Image
|
| 4 |
-
import torch
|
| 5 |
-
from transformers import AutoModelForImageClassification, AutoImageProcessor
|
| 6 |
-
|
| 7 |
-
# Set page config
|
| 8 |
-
st.set_page_config(page_title="Enhanced Solar Panel Fault Detector", layout="wide")
|
| 9 |
-
|
| 10 |
-
# Fault descriptions dictionary
|
| 11 |
-
FAULT_DESCRIPTIONS = {
|
| 12 |
-
"shadowy": {
|
| 13 |
-
"description": "Shadowing occurs when parts of the panel are obscured by objects, reducing energy output.",
|
| 14 |
-
"maintenance": "Remove obstructing objects (e.g., branches, debris) and consider repositioning panels to avoid shadows."
|
| 15 |
-
},
|
| 16 |
-
"cracked": {
|
| 17 |
-
"description": "Cracks on the panel surface can lead to water leakage and reduced performance.",
|
| 18 |
-
"maintenance": "Replace the damaged panel to prevent further degradation and ensure safety."
|
| 19 |
-
},
|
| 20 |
-
"dusty": {
|
| 21 |
-
"description": "Dust or dirt accumulation on the panel surface reduces sunlight absorption.",
|
| 22 |
-
"maintenance": "Clean panels regularly with water and a soft cloth to restore efficiency."
|
| 23 |
-
},
|
| 24 |
-
"hot_spot": {
|
| 25 |
-
"description": "Hot spots indicate localized overheating, often due to defects or debris.",
|
| 26 |
-
"maintenance": "Inspect for debris or defects; consult a technician for potential panel replacement."
|
| 27 |
-
}
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
# Load model and processor
|
| 31 |
-
@st.cache_resource
|
| 32 |
-
def load_model():
|
| 33 |
-
model_name = "efficientnet-b0" # Placeholder; replace with actual Hugging Face model
|
| 34 |
-
processor = AutoImageProcessor.from_pretrained(model_name)
|
| 35 |
-
model = AutoModelForImageClassification.from_pretrained(model_name)
|
| 36 |
-
return processor, model
|
| 37 |
-
|
| 38 |
-
processor, model = load_model()
|
| 39 |
-
|
| 40 |
-
# Class labels (based on multi-class classification)
|
| 41 |
-
labels = ["normal", "shadowy", "cracked", "dusty", "hot_spot"]
|
| 42 |
-
|
| 43 |
-
# Function to process image and predict
|
| 44 |
-
def predict_fault(image):
|
| 45 |
-
inputs = processor(images=image, return_tensors="pt")
|
| 46 |
-
with torch.no_grad():
|
| 47 |
-
outputs = model(**inputs)
|
| 48 |
-
probabilities = torch.softmax(outputs.logits, dim=1)
|
| 49 |
-
predicted_idx = torch.argmax(probabilities, dim=1).item()
|
| 50 |
-
confidence = probabilities[0][predicted_idx].item()
|
| 51 |
-
return labels[predicted_idx], confidence
|
| 52 |
-
|
| 53 |
-
# Streamlit UI
|
| 54 |
-
st.title("Enhanced Solar Panel Fault Detector")
|
| 55 |
-
st.markdown("Upload solar panel images to detect faults such as shadowing, cracks, dust, or hot spots. Get detailed insights and maintenance suggestions.")
|
| 56 |
-
|
| 57 |
-
# Tabs for single and batch upload
|
| 58 |
-
tab1, tab2 = st.tabs(["Single Image Analysis", "Batch Image Analysis"])
|
| 59 |
-
|
| 60 |
-
with tab1:
|
| 61 |
-
st.subheader("Single Image Analysis")
|
| 62 |
-
uploaded_file = st.file_uploader("Upload a solar panel image", type=["jpg", "png", "jpeg"])
|
| 63 |
-
|
| 64 |
-
if uploaded_file:
|
| 65 |
-
image = Image.open(uploaded_file).convert("RGB")
|
| 66 |
-
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 67 |
-
|
| 68 |
-
with st.spinner("Analyzing..."):
|
| 69 |
-
fault_type, confidence = predict_fault(image)
|
| 70 |
-
|
| 71 |
-
st.success(f"**Prediction**: {fault_type.capitalize()} (Confidence: {confidence:.2%})")
|
| 72 |
-
|
| 73 |
-
# Display fault details
|
| 74 |
-
if fault_type != "normal":
|
| 75 |
-
fault_details = FAULT_DESCRIPTIONS.get(fault_type, {})
|
| 76 |
-
with st.expander("Fault Details"):
|
| 77 |
-
st.write(f"**Description**: {fault_details.get('description', 'No description available.')}")
|
| 78 |
-
st.write(f"**Maintenance Tips**: {fault_details.get('maintenance', 'No maintenance tips available.')}")
|
| 79 |
-
else:
|
| 80 |
-
st.info("No faults detected. The panel appears to be in good condition.")
|
| 81 |
-
|
| 82 |
-
with tab2:
|
| 83 |
-
st.subheader("Batch Image Analysis")
|
| 84 |
-
uploaded_files = st.file_uploader("Upload multiple solar panel images", type=["jpg", "png", "jpeg"], accept_multiple_files=True)
|
| 85 |
-
|
| 86 |
-
if uploaded_files:
|
| 87 |
-
results = []
|
| 88 |
-
for uploaded_file in uploaded_files:
|
| 89 |
-
image = Image.open(uploaded_file).convert("RGB")
|
| 90 |
-
fault_type, confidence = predict_fault(image)
|
| 91 |
-
results.append({
|
| 92 |
-
"filename": uploaded_file.name,
|
| 93 |
-
"fault_type": fault_type,
|
| 94 |
-
"confidence": confidence,
|
| 95 |
-
"image": image
|
| 96 |
-
})
|
| 97 |
-
|
| 98 |
-
st.subheader("Batch Analysis Results")
|
| 99 |
-
for result in results:
|
| 100 |
-
col1, col2 = st.columns([1, 2])
|
| 101 |
-
with col1:
|
| 102 |
-
st.image(result["image"], caption=result["filename"], width=200)
|
| 103 |
-
with col2:
|
| 104 |
-
st.write(f"**File**: {result['filename']}")
|
| 105 |
-
st.write(f"**Prediction**: {result['fault_type'].capitalize()} (Confidence: {result['confidence']:.2%})")
|
| 106 |
-
if result["fault_type"] != "normal":
|
| 107 |
-
fault_details = FAULT_DESCRIPTIONS.get(result["fault_type"], {})
|
| 108 |
-
st.write(f"**Description**: {fault_details.get('description', 'No description available.')}")
|
| 109 |
-
st.write(f"**Maintenance Tips**: {fault_details.get('maintenance', 'No maintenance tips available.')}")
|
| 110 |
-
else:
|
| 111 |
-
st.write("No faults detected.")
|
| 112 |
-
|
| 113 |
-
# Sidebar with additional info
|
| 114 |
-
st.sidebar.title("About")
|
| 115 |
-
st.sidebar.markdown("""
|
| 116 |
-
This app uses a deep learning model to detect faults in solar panels, such as shadowing, cracks, dust, or hot spots.
|
| 117 |
-
Enhanced features include:
|
| 118 |
-
- Multi-class fault detection
|
| 119 |
-
- Confidence scores
|
| 120 |
-
- Detailed fault descriptions and maintenance tips
|
| 121 |
-
- Batch image processing
|
| 122 |
-
""")
|
| 123 |
-
st.sidebar.markdown("[Source Code](https://huggingface.co/spaces/your-username/Solar_Panel_Fault_Detector_Enhanced)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|