from fastapi import FastAPI, UploadFile, File from models.object_detection import detect_faults from models.thermal_anomaly_detection import detect_thermal_anomalies from models.energy_anomaly_detection import detect_energy_anomalies import cv2 import numpy as np app = FastAPI() @app.post("/detect_faults/") async def detect_faults_from_video(file: UploadFile = File(...)): # Save the uploaded file temporarily file_location = f"data/{file.filename}" with open(file_location, "wb") as buffer: buffer.write(file.file.read()) # Read video or image for object detection video = cv2.VideoCapture(file_location) result = detect_faults(video) return {"faults_detected": result} @app.post("/detect_thermal_anomalies/") async def detect_thermal_anomalies_from_image(file: UploadFile = File(...)): # Save the uploaded thermal image file_location = f"data/{file.filename}" with open(file_location, "wb") as buffer: buffer.write(file.file.read()) # Load image and run thermal anomaly detection result = detect_thermal_anomalies(file_location) return {"thermal_anomalies": result} @app.post("/detect_energy_anomalies/") async def detect_energy_anomalies_from_data(file: UploadFile = File(...)): # Save energy data file (CSV, JSON, etc.) file_location = f"data/{file.filename}" with open(file_location, "wb") as buffer: buffer.write(file.file.read()) # Run energy anomaly detection result = detect_energy_anomalies(file_location) return {"energy_anomalies": result}