InspectWiseAI / main.py
sreekar8811's picture
Upload 3 files
13d7ba8 verified
from fastapi import FastAPI, UploadFile, File, Form, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from typing import Optional
import uvicorn
from ai_models import AIInspectionSystem
app = FastAPI(title="InspectWise AI Backend")
# Enable CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
ai_service = AIInspectionSystem()
@app.post("/inspect")
async def inspect(
image: Optional[UploadFile] = File(None),
text: Optional[str] = Form(None),
location: Optional[str] = Form(None)
):
if not image and not text:
raise HTTPException(status_code=400, detail="Either image or text must be provided")
try:
image_bytes = await image.read() if image else None
result = ai_service.inspect(image_bytes=image_bytes, text=text)
return result
except Exception as e:
print("Inspection error:", e)
raise HTTPException(status_code=500, detail="AI processing failed")
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)