File size: 3,563 Bytes
4e43f51
 
2a2e057
7fd2308
2a2e057
7ba6cbc
4e43f51
58ab919
 
 
 
 
 
 
 
 
654e814
 
 
 
 
58ab919
 
 
 
 
 
 
 
 
4e43f51
21e0e83
 
58ab919
4e43f51
58ab919
 
 
 
 
 
 
 
 
 
 
654e814
58ab919
 
654e814
 
58ab919
654e814
 
 
58ab919
 
 
 
 
 
 
 
 
 
654e814
 
58ab919
4e43f51
58ab919
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import gradio as gr
import pandas as pd
import joblib

# Load the trained model
model = joblib.load('random_forest_model.pkl')  # replace with your model path

# Define the function to make predictions
def predict_price(host_id, latitude, longitude, number_of_reviews, calculated_host_listings_count, 
                  room_type_Private_room, room_type_Shared_room, 
                  neighbourhood_group_Brooklyn, neighbourhood_group_Manhattan, 
                  neighbourhood_group_Queens, neighbourhood_group_Staten_Island, 
                  neighbourhood_Arden_Heights, neighbourhood_Arrochar, neighbourhood_Arverne):
    
    # Prepare input data
    custom_data = pd.DataFrame(0, index=[0], columns=model.feature_names_in_)
    custom_data.at[0, 'host_id'] = host_id
    custom_data.at[0, 'latitude'] = latitude
    custom_data.at[0, 'longitude'] = longitude
    custom_data.at[0, 'number_of_reviews'] = number_of_reviews
    custom_data.at[0, 'calculated_host_listings_count'] = calculated_host_listings_count
    custom_data.at[0, 'room_type_Private room'] = room_type_Private_room
    custom_data.at[0, 'room_type_Shared room'] = room_type_Shared_room
    custom_data.at[0, 'neighbourhood_group_Brooklyn'] = neighbourhood_group_Brooklyn
    custom_data.at[0, 'neighbourhood_group_Manhattan'] = neighbourhood_group_Manhattan
    custom_data.at[0, 'neighbourhood_group_Queens'] = neighbourhood_group_Queens
    custom_data.at[0, 'neighbourhood_group_Staten Island'] = neighbourhood_group_Staten_Island
    custom_data.at[0, 'neighbourhood_Arden Heights'] = neighbourhood_Arden_Heights
    custom_data.at[0, 'neighbourhood_Arrochar'] = neighbourhood_Arrochar
    custom_data.at[0, 'neighbourhood_Arverne'] = neighbourhood_Arverne

    # Make prediction
    predicted_price = model.predict(custom_data)
    return f"The predicted house price is: ${predicted_price[0]:.2f}"

# Set up the Gradio interface
title = "House Price Predictor"
description = """
This application predicts the price of a house based on several features. 
Please fill in the following details to get a prediction:
- **Latitude**: Geographic coordinate.
- **Longitude**: Geographic coordinate.
- **Number of Reviews**: Total reviews received by the listing.
- **Calculated Host Listings Count**: Total number of listings by the host.
- **Room Type**: Select whether the room is a private or shared room.
- **Neighbourhood Groups**: Select the corresponding neighbourhood group.

After entering the information, click on the **'Submit'** button to see the predicted price.
"""

inputs = [
   
    gr.Number(label="Latitude"),
    gr.Number(label="Longitude"),
    gr.Number(label="Number of Reviews"),
    gr.Number(label="Calculated Host Listings Count"),
    gr.Radio(label="Room Type - Private Room", choices=[0, 1]),
    gr.Radio(label="Room Type - Shared Room", choices=[0, 1]),
    gr.Radio(label="Neighbourhood Group - Brooklyn", choices=[0, 1]),
    gr.Radio(label="Neighbourhood Group - Manhattan", choices=[0, 1]),
    gr.Radio(label="Neighbourhood Group - Queens", choices=[0, 1]),
    gr.Radio(label="Neighbourhood Group - Staten Island", choices=[0, 1]),
    gr.Radio(label="Neighbourhood - Arden Heights", choices=[0, 1]),
    gr.Radio(label="Neighbourhood - Arrochar", choices=[0, 1]),
    gr.Radio(label="Neighbourhood - Arverne", choices=[0, 1]),
]

output = gr.Textbox(label="Predicted Price", placeholder="The predicted price will appear here.", lines=2)

gr.Interface(fn=predict_price, inputs=inputs, outputs=output, title=title, description=description).launch()