|
import gradio as gr |
|
import pandas as pd |
|
import joblib |
|
|
|
|
|
loaded_model = joblib.load('random_forest_model.pkl') |
|
|
|
|
|
def predict(host_id, neighbourhood_group, neighbourhood, room_type, latitude, longitude, number_of_reviews, calculated_host_listings_count): |
|
|
|
input_data = pd.DataFrame({ |
|
'host_id': [host_id], |
|
'neighbourhood_group': [neighbourhood_group], |
|
'neighbourhood': [neighbourhood], |
|
'room_type': [room_type], |
|
'latitude': [latitude], |
|
'longitude': [longitude], |
|
'number_of_reviews': [number_of_reviews], |
|
'calculated_host_listings_count': [calculated_host_listings_count] |
|
}) |
|
|
|
|
|
input_data = pd.get_dummies(input_data, columns=['room_type', 'neighbourhood_group', 'neighbourhood'], drop_first=True) |
|
|
|
|
|
input_data = input_data.reindex(columns=X.columns, fill_value=0) |
|
|
|
|
|
predicted_price = loaded_model.predict(input_data) |
|
return predicted_price[0] |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict, |
|
inputs=[ |
|
gr.Number(label="Host ID"), |
|
gr.Dropdown(["Manhattan", "Brooklyn", "Queens", "Bronx", "Staten Island"], label="Neighbourhood Group"), |
|
gr.Dropdown(["Upper East Side", "Chelsea", "Williamsburg"], label="Neighbourhood"), |
|
gr.Dropdown(["Entire home/apt", "Private room", "Shared room"], label="Room Type"), |
|
gr.Number(label="Latitude"), |
|
gr.Number(label="Longitude"), |
|
gr.Number(label="Number of Reviews"), |
|
gr.Number(label="Calculated Host Listings Count") |
|
], |
|
outputs="number", |
|
title="NYC Rental Price Prediction", |
|
description="Predict the rental price of an Airbnb listing in NYC." |
|
) |
|
|
|
|
|
iface.launch() |
|
|