File size: 734 Bytes
7749774
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bbf029a
 
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
from fastapi import FastAPI
from models import PredictReq
import pickle
import json
import numpy as np

app = FastAPI()

ml_model = None
# Load the XGBoost model
with open('xgb_model.pkl', 'rb') as model_file:
	ml_model = pickle.load(model_file)

# This is just the normal getter api to check if working of the entire backend
@app.get("/")
def foo():
	return {
		"status": "House Price Prediction"
	}

@app.post("/predict_house_price")
def predice_house_price(req: PredictReq):
	inp = np.array([[
				req.medInc,
				req.houseAge,
				req.avgRooms,
				req.avgBdrms,
				req.population,
				req.avgOccup,
				req.latitude,
				req.longitude,
			]])

	prediction = ml_model.predict(inp)[0]

	return {
		'price': str(prediction*100)
	}