Spaces:
Sleeping
Sleeping
Download app.py from Demorax3/HotelPredictionTest: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/Demorax3/HotelPredictionTest/resolve/main/app.py
- Command line
-
hf download hf://spaces/Demorax3/HotelPredictionTest/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Demorax3/HotelPredictionTest/resolve/main/app.py
1 kB
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from huggingface_hub import hf_hub_download | |
| import joblib | |
| import pandas as pd | |
| import xgboost as xgb | |
| import os | |
| app = FastAPI() | |
| HF_REPO = os.environ.get("HF_REPO", "Demorax3/hotel-country-classifier") | |
| model = xgb.XGBClassifier() | |
| model.load_model(hf_hub_download(HF_REPO, "xgb_model.json")) | |
| encoder = joblib.load(hf_hub_download(HF_REPO, "target_encoder.pkl")) | |
| le = joblib.load(hf_hub_download(HF_REPO, "label_encoder.pkl")) | |
| class HotelInput(BaseModel): | |
| score: float | |
| num_reviews: int | |
| price: float | |
| room_type: str | |
| city: str | |
| def predict(data: HotelInput): | |
| df = pd.DataFrame([{ | |
| "Score": data.score, | |
| "Number_Reviews": data.num_reviews, | |
| "Price": data.price, | |
| "Room_Type": data.room_type, | |
| "City": data.city, | |
| }]) | |
| df_enc = encoder.transform(df) | |
| pred = model.predict(df_enc) | |
| country = le.inverse_transform(pred)[0] | |
| return {"country": country} | |