import streamlit as st import cv2 from services.video_service import process_video from services.detection_service import detect_faults_solar, detect_faults_windmill from services.thermal_service import detect_hotspots from services.shadow_detection import detect_shadows from PIL import Image import os # Load models for solar and windmill detection from models.solar_model import load_solar_model from models.windmill_model import load_windmill_model # Root folder for videos VIDEO_FOLDER = "./data" # Ensure your videos are placed in this folder def main(): st.title("Solar Panel and Windmill Fault Detection") # Choose video for live feed simulation video_file = st.selectbox("Choose a Video", [f for f in os.listdir(VIDEO_FOLDER) if f.endswith('.mp4')]) if video_file: video_path = os.path.join(VIDEO_FOLDER, video_file) st.write(f"Processing video: {video_file}") # Open the video using OpenCV cap = cv2.VideoCapture(video_path) if not cap.isOpened(): st.error("Error opening video stream or file") return # Placeholder for displaying frames stframe = st.empty() # Choose fault detection type choice = st.selectbox("Choose Fault Detection", ["Solar Panel", "Windmill"]) model = None if choice == "Solar Panel": model = load_solar_model() else: model = load_windmill_model() while cap.isOpened(): ret, frame = cap.read() if not ret: break # Convert the frame to RGB (Streamlit uses RGB) frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # Preprocess the frame and detect faults faults = detect_faults_solar(model, frame_rgb) if choice == "Solar Panel" else detect_faults_windmill(model, frame_rgb) # Draw bounding boxes and labels for detected faults for fault in faults: x, y = int(fault['location'][0]), int(fault['location'][1]) cv2.putText(frame, f"Fault: {fault['type']}", (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 0, 255), 2) cv2.rectangle(frame, (x-20, y-20), (x+80, y+40), (0, 0, 255), 2) # Update the live feed with the processed frame stframe.image(frame_rgb, channels="RGB", use_column_width=True) cap.release() if __name__ == "__main__": main()