fahad1995 commited on
Commit
5efd87b
·
verified ·
1 Parent(s): 7fd2308

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -6,20 +6,19 @@ import joblib # or import pickle if you used it to save your model
6
  model = joblib.load('random_forest_model.pkl') # replace with your model path
7
 
8
  # Function to predict price
9
- def predict_price(host_id, neighbourhood_group, room_type, price, reviews, calculated_host_listings_count, latitude, longitude):
10
  # Create a DataFrame for the input data
11
  custom_data = pd.DataFrame({
12
  'host_id': [host_id],
13
- 'neighbourhood_group_Brooklyn': [1 if neighbourhood_group == 'Brooklyn' else 0],
14
- 'neighbourhood_group_Manhattan': [1 if neighbourhood_group == 'Manhattan' else 0],
15
- 'neighbourhood_group_Queens': [1 if neighbourhood_group == 'Queens' else 0],
16
- 'neighbourhood_group_Bronx': [1 if neighbourhood_group == 'Bronx' else 0],
17
- 'neighbourhood_group_Staten Island': [1 if neighbourhood_group == 'Staten Island' else 0],
18
  'room_type_Shared room': [1 if room_type == 'Shared room' else 0],
19
  'room_type_Private room': [1 if room_type == 'Private room' else 0],
20
  'room_type_Entire home/apt': [1 if room_type == 'Entire home/apt' else 0],
21
- 'price': [price],
22
- 'number_of_reviews': [reviews],
23
  'calculated_host_listings_count': [calculated_host_listings_count],
24
  'latitude': [latitude],
25
  'longitude': [longitude]
@@ -36,7 +35,6 @@ interface = gr.Interface(
36
  gr.Number(label="Host ID"),
37
  gr.Dropdown(["Brooklyn", "Manhattan", "Queens", "Bronx", "Staten Island"], label="Neighbourhood Group"),
38
  gr.Dropdown(["Shared room", "Private room", "Entire home/apt"], label="Room Type"),
39
- gr.Number(label="Price"),
40
  gr.Number(label="Number of Reviews"),
41
  gr.Number(label="Calculated Host Listings Count"),
42
  gr.Number(label="Latitude"),
@@ -49,3 +47,7 @@ interface = gr.Interface(
49
 
50
  # Launch the interface
51
  interface.launch()
 
 
 
 
 
6
  model = joblib.load('random_forest_model.pkl') # replace with your model path
7
 
8
  # Function to predict price
9
+ def predict_price(host_id, neighbourhood_group, room_type, number_of_reviews, calculated_host_listings_count, latitude, longitude):
10
  # Create a DataFrame for the input data
11
  custom_data = pd.DataFrame({
12
  'host_id': [host_id],
13
+ 'neighbourhood_Brooklyn': [1 if neighbourhood_group == 'Brooklyn' else 0],
14
+ 'neighbourhood_Manhattan': [1 if neighbourhood_group == 'Manhattan' else 0],
15
+ 'neighbourhood_Queens': [1 if neighbourhood_group == 'Queens' else 0],
16
+ 'neighbourhood_Bronx': [1 if neighbourhood_group == 'Bronx' else 0],
17
+ 'neighbourhood_Staten Island': [1 if neighbourhood_group == 'Staten Island' else 0],
18
  'room_type_Shared room': [1 if room_type == 'Shared room' else 0],
19
  'room_type_Private room': [1 if room_type == 'Private room' else 0],
20
  'room_type_Entire home/apt': [1 if room_type == 'Entire home/apt' else 0],
21
+ 'number_of_reviews': [number_of_reviews],
 
22
  'calculated_host_listings_count': [calculated_host_listings_count],
23
  'latitude': [latitude],
24
  'longitude': [longitude]
 
35
  gr.Number(label="Host ID"),
36
  gr.Dropdown(["Brooklyn", "Manhattan", "Queens", "Bronx", "Staten Island"], label="Neighbourhood Group"),
37
  gr.Dropdown(["Shared room", "Private room", "Entire home/apt"], label="Room Type"),
 
38
  gr.Number(label="Number of Reviews"),
39
  gr.Number(label="Calculated Host Listings Count"),
40
  gr.Number(label="Latitude"),
 
47
 
48
  # Launch the interface
49
  interface.launch()
50
+
51
+ print("Custom Data Columns:", custom_data.columns.tolist())
52
+ print("Model Training Features:", model.feature_names_in_)
53
+