File size: 1,944 Bytes
4e43f51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
import gradio as gr
import pandas as pd
import joblib

# Load your Random Forest model
loaded_model = joblib.load('random_forest_model.pkl')

# Function to make predictions
def predict(host_id, neighbourhood_group, neighbourhood, room_type, latitude, longitude, number_of_reviews, calculated_host_listings_count):
    # Prepare input data as DataFrame
    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]
    })

    # One-hot encode the categorical features
    input_data = pd.get_dummies(input_data, columns=['room_type', 'neighbourhood_group', 'neighbourhood'], drop_first=True)
    
    # Ensure the input data has the same columns as the training data
    input_data = input_data.reindex(columns=X.columns, fill_value=0)

    # Make the prediction
    predicted_price = loaded_model.predict(input_data)
    return predicted_price[0]

# Create a Gradio interface
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."
)

# Launch the interface
iface.launch()