Spaces:
No application file
No application file
| import torch | |
| import cv2 | |
| from PIL import Image | |
| from torchvision import transforms | |
| import numpy as np | |
| # Dummy models – replace with your own | |
| def load_model(path): | |
| model = torch.load(path, map_location="cpu") | |
| model.eval() | |
| return model | |
| thermal_model = load_model("models/thermal_fault_model.pt") | |
| crack_model = load_model("models/crack_detector_model.pt") | |
| dust_model = load_model("models/dust_detector_model.pt") | |
| def detect_faults(image): | |
| transform = transforms.Compose([ | |
| transforms.ToPILImage(), | |
| transforms.Resize((224, 224)), | |
| transforms.ToTensor(), | |
| ]) | |
| img_tensor = transform(image).unsqueeze(0) | |
| results = [] | |
| output_img = image.copy() | |
| # Simulated prediction | |
| if torch.rand(1).item() > 0.5: | |
| results.append({ | |
| "type": "Thermal Fault", | |
| "location": "Panel 12-B", | |
| "confidence": 0.93 | |
| }) | |
| cv2.putText(output_img, "Thermal Fault", (50, 50), | |
| cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2) | |
| if torch.rand(1).item() > 0.5: | |
| results.append({ | |
| "type": "Crack Detected", | |
| "location": "Panel 9-C", | |
| "confidence": 0.88 | |
| }) | |
| cv2.putText(output_img, "Crack", (150, 100), | |
| cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2) | |
| if torch.rand(1).item() > 0.5: | |
| results.append({ | |
| "type": "Dust Coverage", | |
| "location": "Panel 3-A", | |
| "confidence": 0.91 | |
| }) | |
| cv2.putText(output_img, "Dust", (200, 150), | |
| cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 0), 2) | |
| return results, output_img | |