-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
46 lines (38 loc) · 1.46 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from fastapi import FastAPI, HTTPException
from schemas import (
ApartmentRequest,
ApartmentResponse,
BreastCancerRequest,
BreastCancerResponse,
SalaryRequest,
SalaryResponse,
)
from services import ApartmentService, BreastCancerPredictionService, SalaryService
app = FastAPI()
@app.post("/lr/predict-house-price/")
def predict_house_price(request: ApartmentRequest) -> ApartmentResponse:
apartment_service = ApartmentService()
try:
response = apartment_service.predict(request)
return response
except Exception as e:
error = f"Failed to predict house price. (error: {str(e)})"
raise HTTPException(status_code=400, detail=error)
@app.post("/lr/predict-salary")
def predict_salary(request: SalaryRequest) -> SalaryResponse:
salary_service = SalaryService()
try:
response = salary_service.predict(request)
return response
except Exception as e:
error = f"Failed to predict salary. (error: {str(e)})"
raise HTTPException(status_code=400, detail=error)
@app.post("/lr/predict-breast-cancer")
def predict_breast_cancer(request: BreastCancerRequest) -> BreastCancerResponse:
breast_cancer_service = BreastCancerPredictionService()
try:
response = breast_cancer_service.predict(request)
return response
except Exception as e:
error = f"Failed to predict breast cancer. (error: {str(e)})"
raise HTTPException(status_code=400, detail=error)