Tigernawin's picture
Update app.py
e859d8d verified
# app.py
import streamlit as st
from PIL import Image, ImageDraw
from modules.thermal_fault_detection import detect_faults, CUSTOM_CLASSES
# Streamlit page configuration
st.set_page_config(page_title="Solar Panel Thermal Fault Detector", layout="centered")
st.title("πŸ” Solar Panel Thermal Fault Detection Dashboard")
st.markdown("""
This AI-powered app analyzes thermal images from drones to detect:
- πŸ”₯ Overheating
- 🌫️ Dust Accumulation
- πŸ”§ Physical Breakage
""")
# Upload image
uploaded_image = st.file_uploader("Upload a thermal image of a solar panel", type=["jpg", "jpeg", "png", "webp"])
# Confidence threshold slider
threshold = st.slider("Detection Confidence Threshold", 0.0, 1.0, 0.1, 0.05)
# Function to draw all faults on the image
def draw_all_faults(image, results):
draw = ImageDraw.Draw(image)
for label, confidence, box in results:
x1, y1, x2, y2 = box
draw.rectangle([x1, y1, x2, y2], outline="red", width=3)
draw.text((x1, y1 - 10), f"{label} ({confidence:.2f})", fill="red")
return image
# Main logic
if uploaded_image:
image = Image.open(uploaded_image).convert("RGB")
st.image(image, caption="Uploaded Thermal Image", use_column_width=True)
with st.spinner("Analyzing for thermal faults..."):
results = detect_faults(image, threshold=threshold)
if results:
fault_types = sorted(set([fault[0] for fault in results]))
st.error(f"❗ Faults Detected: {', '.join(fault_types)}")
for label, confidence, _ in results:
st.write(f"- πŸ”΄ **Type:** {label} | **Confidence:** {confidence:.2f}")
image_with_faults = draw_all_faults(image.copy(), results)
st.image(image_with_faults, caption="πŸ–ΌοΈ Highlighted Faults", use_column_width=True)
else:
st.success("βœ… No faults detected.")