-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e697ab1
commit af25faa
Showing
7 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from uuid import UUID | ||
|
||
from fastapi import APIRouter, Depends, status | ||
from src.apis.utils.utils import generate_error_responses | ||
from src.auth.auth_bearer import auth_required | ||
from src.schemas.inference_schema import InferenceResponseSchema, StructuredDataSchema | ||
from src.services.inference_srv import InferenceSrv | ||
|
||
router = APIRouter(tags=["inference"]) | ||
|
||
|
||
@router.post( | ||
"/inference", | ||
summary="Inference endpoint", | ||
description="Inference endpoint", | ||
status_code=status.HTTP_200_OK, | ||
response_description="Inference successful", | ||
responses=generate_error_responses(status.HTTP_403_FORBIDDEN), | ||
response_model=InferenceResponseSchema, | ||
) | ||
async def inference( | ||
structured_data_schema: StructuredDataSchema, inference_srv: InferenceSrv = Depends(InferenceSrv), user_id: UUID = Depends(auth_required) | ||
): | ||
prediction = await inference_srv.predict(structured_data_schema.dict()) | ||
return InferenceResponseSchema(prediction=prediction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from pydantic import BaseModel, Field | ||
|
||
|
||
class StructuredDataSchema(BaseModel): | ||
# categorical | ||
manufacturer: str | ||
model: str | ||
fuel: str | ||
sold_by: bool # True for dealer, False for private | ||
gearbox: bool # True for automatic, False for manual | ||
chassis: str | ||
|
||
# numerical | ||
km: int | ||
power: int | ||
engine: int | ||
year: int | ||
|
||
|
||
class InferenceResponseSchema(BaseModel): | ||
prediction: float = Field(..., example=10000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import random | ||
|
||
from fastapi import Depends | ||
from src.repositories.sqlalchemy_repo import SQLAlchemyRepository | ||
from src.services.abstract_srv import AbstractService | ||
|
||
|
||
class InferenceSrv(AbstractService): | ||
_repository: SQLAlchemyRepository | ||
|
||
def __init__(self, repo: SQLAlchemyRepository = Depends(SQLAlchemyRepository)): | ||
super().__init__(repo) | ||
|
||
async def preprocess_data(self, data): | ||
# TODO | ||
return data | ||
|
||
async def predict(self, data): | ||
# TODO | ||
data = await self.preprocess_data(data) | ||
return random.randint(1000, 50000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters