initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from app.models.prediction import HousePredictionInput, HousePredictionOutput
|
||||
from app.services.ml_model import HousePricePredictor
|
||||
|
||||
router = APIRouter()
|
||||
model = HousePricePredictor()
|
||||
|
||||
@router.post("/predict",
|
||||
response_model=HousePredictionOutput,
|
||||
summary="Predict house price",
|
||||
description="Predicts the price of a house based on its features"
|
||||
)
|
||||
async def predict_price(input_data: HousePredictionInput) -> HousePredictionOutput:
|
||||
try:
|
||||
predicted_price, confidence_score, similar_listings = model.predict(
|
||||
input_data.square_feet,
|
||||
input_data.bedrooms,
|
||||
input_data.bathrooms
|
||||
)
|
||||
|
||||
return HousePredictionOutput(
|
||||
predicted_price=predicted_price,
|
||||
confidence_score=confidence_score,
|
||||
similar_listings=similar_listings
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
Reference in New Issue
Block a user