File size: 2,222 Bytes
f2bbea0
d63f5af
f676d6d
 
 
 
f2bbea0
f676d6d
 
 
f2bbea0
 
 
f676d6d
 
f2bbea0
 
 
 
 
 
 
 
 
 
 
f676d6d
 
 
f2bbea0
 
 
 
 
 
 
 
 
 
 
f676d6d
 
 
f2bbea0
 
 
 
 
 
 
 
 
 
01ce2c5
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from fastapi import FastAPI, UploadFile, File, HTTPException
from models.object_detection import detect_faults_from_huggingface
from models.thermal_anomaly_detection import detect_thermal_anomalies
from models.energy_anomaly_detection import detect_energy_anomalies
import cv2
import numpy as np
import os

app = FastAPI()

# Ensure the data directory exists
os.makedirs('data', exist_ok=True)

@app.post("/detect_faults/")
async def detect_faults_from_video(file: UploadFile = File(...)):
    try:
        # Save the uploaded image for object detection
        file_location = f"data/{file.filename}"
        with open(file_location, "wb") as buffer:
            buffer.write(await file.read())
        
        # Run object detection on image using Hugging Face model
        result = detect_faults_from_huggingface(file_location)
        return {"faults_detected": result}
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Error processing fault detection: {str(e)}")

@app.post("/detect_thermal_anomalies/")
async def detect_thermal_anomalies_from_image(file: UploadFile = File(...)):
    try:
        # Save the uploaded thermal image
        file_location = f"data/{file.filename}"
        with open(file_location, "wb") as buffer:
            buffer.write(await file.read())
        
        # Load image and run thermal anomaly detection
        result = detect_thermal_anomalies(file_location)
        return {"thermal_anomalies": result}
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Error processing thermal anomaly detection: {str(e)}")

@app.post("/detect_energy_anomalies/")
async def detect_energy_anomalies_from_data(file: UploadFile = File(...)):
    try:
        # Save energy data file (CSV, JSON, etc.)
        file_location = f"data/{file.filename}"
        with open(file_location, "wb") as buffer:
            buffer.write(await file.read())
        
        # Run energy anomaly detection
        result = detect_energy_anomalies(file_location)
        return {"energy_anomalies": result}
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Error processing energy anomaly detection: {str(e)}")