caslabs commited on
Commit
670df98
1 Parent(s): e38fde7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -3,32 +3,24 @@ import pandas as pd
3
  import xgboost as xgb
4
  from huggingface_hub import hf_hub_download
5
 
6
- # Download and load the model from the Hugging Face repository
7
- model_path = hf_hub_download(
8
- repo_id='caslabs/xgboost-home-price-predictor',
9
- filename='xgboost_model.json',
10
- repo_type='model'
11
- )
12
-
13
- loaded_model = xgb.XGBRegressor()
14
- loaded_model.load_model(model_path)
15
 
16
  # Define the prediction function
17
- def predict_price(data):
18
- # Parse the input data
19
- input_data = pd.DataFrame([data])
20
-
21
- # Make a prediction
22
- predicted_price = loaded_model.predict(input_data)[0]
23
- return {"predicted_price": round(predicted_price, 2)}
24
 
25
- # Define the API interface with Gradio
26
  iface = gr.Interface(
27
  fn=predict_price,
28
- inputs=gr.JSON(), # Accept JSON input
29
- outputs=gr.JSON(), # Return JSON output
30
  title="Home Price Prediction API",
31
- description="Provide property details in JSON format, and the model will return the predicted adjusted sale price."
32
  )
33
 
34
- iface.launch()
 
3
  import xgboost as xgb
4
  from huggingface_hub import hf_hub_download
5
 
6
+ # Download and load the model
7
+ model_path = hf_hub_download(repo_id="caslabs/xgboost-home-price-predictor", filename="xgboost_model.json")
8
+ model = xgb.XGBRegressor()
9
+ model.load_model(model_path)
 
 
 
 
 
10
 
11
  # Define the prediction function
12
+ def predict_price(features):
13
+ df = pd.DataFrame([features])
14
+ predicted_price = model.predict(df)[0]
15
+ return {"predicted_price": predicted_price}
 
 
 
16
 
17
+ # Set up Gradio interface as an API endpoint
18
  iface = gr.Interface(
19
  fn=predict_price,
20
+ inputs=gr.JSON(),
21
+ outputs=gr.JSON(),
22
  title="Home Price Prediction API",
23
+ description="Predict home price based on features"
24
  )
25
 
26
+ iface.launch()