File size: 1,193 Bytes
7690851 de597ec 7690851 aeaf551 7690851 de597ec 7690851 aeaf551 1457ba8 aeaf551 7690851 aeaf551 7690851 de597ec 7690851 de597ec |
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 |
from fastapi import FastAPI, HTTPException
import logging
from src.config import Config
from src.models import SensorData, AnalysisResponse
from src.services import AnalysisService
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
config = Config()
app = FastAPI(title=config.APP_TITLE, version=config.APP_VERSION)
service = AnalysisService(config)
@app.post("/analyze", response_model=AnalysisResponse)
async def analyze_sensor_data(data: SensorData):
try:
logger.info(f"Processing request with {len(data.vdc1)} voltage and {len(data.idc1)} current data points")
ml_output, agent_output = service.analyze(data.vdc1, data.idc1, data.api_key, data.asset_id)
return AnalysisResponse(ml_output=ml_output, agent_output=agent_output)
except HTTPException:
raise
except Exception as e:
logger.error(f"Error processing request: {e}")
raise HTTPException(status_code=500, detail=str(e))
@app.get("/")
async def root():
return {"message": "Solar PV Predictive Maintenance", "endpoint": "/analyze (POST)"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host=config.HOST, port=config.PORT) |