Create libs/ai-services/ with FastAPI app providing: - POST /avm/predict — XGBoost-backed property price prediction (heuristic fallback) - POST /avm/extract-features — Vietnamese NLP feature extraction from listing text - POST /moderation/check — content moderation with rule-based flagging - GET /health — health check endpoint Includes Dockerfile (Python 3.12), docker-compose integration, Pydantic models, and 9 passing tests covering all endpoints. Co-Authored-By: Paperclip <noreply@paperclip.ing>
24 lines
782 B
Python
24 lines
782 B
Python
from fastapi import APIRouter
|
|
|
|
from app.models.avm import (
|
|
AVMPredictRequest,
|
|
AVMPredictResponse,
|
|
FeatureExtractRequest,
|
|
FeatureExtractResponse,
|
|
)
|
|
from app.services.avm_service import avm_service, feature_extract_service
|
|
|
|
router = APIRouter(prefix="/avm", tags=["AVM"])
|
|
|
|
|
|
@router.post("/predict", response_model=AVMPredictResponse)
|
|
def predict(req: AVMPredictRequest) -> AVMPredictResponse:
|
|
"""Predict property price using the Automated Valuation Model."""
|
|
return avm_service.predict(req)
|
|
|
|
|
|
@router.post("/extract-features", response_model=FeatureExtractResponse)
|
|
def extract_features(req: FeatureExtractRequest) -> FeatureExtractResponse:
|
|
"""Extract real-estate features from Vietnamese listing text."""
|
|
return feature_extract_service.extract(req)
|