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 numpy as np # Load models for solar and windmill detection from models.solar_model import load_solar_model from models.windmill_model import load_windmill_model def main(): st.title("Solar Panel and Windmill Fault Detection") # Upload video file uploaded_file = st.file_uploader("Upload a Video (MP4 or AVI)", type=["mp4", "avi"]) if uploaded_file is not None: video_path = "/tmp/" + uploaded_file.name with open(video_path, "wb") as f: f.write(uploaded_file.read()) # Open the video using OpenCV cap = cv2.VideoCapture(video_path) # Check if video was opened successfully if not cap.isOpened(): st.error("Error opening video stream or file") return # Process frames in real-time 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) # Show faults on the frame for fault in faults: # For example, draw bounding boxes for faults on the frame 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()