20 lines
813 B
Python
20 lines
813 B
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
from typing import List
|
|
from schemas.schemas import LaptopCreate, LaptopResponse, PredictPriceResponse
|
|
from services.service import LaptopService
|
|
import os
|
|
|
|
router = APIRouter()
|
|
|
|
# Инициализация сервиса
|
|
MODEL_PATH = os.getenv("MODEL_PATH", "laptop_price_model.pkl")
|
|
FEATURE_COLUMNS_PATH = os.getenv("FEATURE_COLUMNS_PATH", "feature_columns.pkl")
|
|
laptop_service = LaptopService(model_path=MODEL_PATH, feature_columns_path=FEATURE_COLUMNS_PATH)
|
|
|
|
@router.post("/predict_price/", response_model=PredictPriceResponse)
|
|
def predict_price(data: LaptopCreate):
|
|
try:
|
|
return laptop_service.predict_price(data.dict())
|
|
except Exception as e:
|
|
raise HTTPException(status_code=400, detail=str(e)) |