Spaces:
Sleeping
Sleeping
Download server.py from gruhit-patel/deployment_app: direct link, hf CLI and curl.
- Browser
- Download file 734 Bytes
-
https://huggingface.co/spaces/gruhit-patel/deployment_app/resolve/main/server.py
- Command line
-
hf download hf://spaces/gruhit-patel/deployment_app/server.py
-
curl -L -o server.py https://huggingface.co/spaces/gruhit-patel/deployment_app/resolve/main/server.py
734 Bytes
| 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 | |
| def foo(): | |
| return { | |
| "status": "House Price Prediction" | |
| } | |
| 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) | |
| } | |