jellyelly commited on
Commit
9459318
1 Parent(s): 7c1e667

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -3,44 +3,42 @@ import joblib
3
  import numpy as np
4
  import pandas as pd
5
 
6
- # Load the model and unique brand values
7
  model = joblib.load('model.joblib')
8
  unique_values = joblib.load('unique_values.joblib')
9
- brand_values = unique_values['Brand']
10
 
11
  # Define the prediction function
12
- def predict(brand, screen_size, resolution_width, resolution_height):
13
  # Convert inputs to appropriate types
14
- screen_size = float(screen_size)
15
- resolution_width = int(resolution_width)
16
- resolution_height = int(resolution_height)
17
 
18
  # Prepare the input array for prediction
19
  input_data = pd.DataFrame({
20
- 'Brand': [brand],
21
- 'Screen Size': [screen_size],
22
- 'Resolution (Width)': [resolution_width],
23
- 'Resolution (Height)': [resolution_height]
24
  })
25
 
26
  # Perform the prediction
27
  prediction = model.predict(input_data)
28
 
29
- return prediction[0]
30
 
31
  # Create the Gradio interface
32
  interface = gr.Interface(
33
  fn=predict,
34
  inputs=[
35
- gr.Dropdown(choices=list(brand_values), label="Brand"),
36
- gr.Textbox(label="Screen Size"),
37
- gr.Textbox(label="Resolution (Width)"),
38
- gr.Textbox(label="Resolution (Height)")
39
  ],
40
  outputs="text",
41
- title="Monitor Predictor",
42
- description="Enter the brand, screen size, and resolution to predict the target value."
43
  )
44
 
 
 
45
  # Launch the app
46
- interface.launch()
 
3
  import numpy as np
4
  import pandas as pd
5
 
 
6
  model = joblib.load('model.joblib')
7
  unique_values = joblib.load('unique_values.joblib')
8
+ neighborhood_values = unique_values['Neighborhood']
9
 
10
  # Define the prediction function
11
+ def predict(neighborhood, house_size, num_rooms):
12
  # Convert inputs to appropriate types
13
+ house_size = float(house_size)
14
+ num_rooms = int(num_rooms)
 
15
 
16
  # Prepare the input array for prediction
17
  input_data = pd.DataFrame({
18
+ 'Neighborhood': [neighborhood],
19
+ 'House Size': [house_size],
20
+ 'Number of Rooms': [num_rooms]
 
21
  })
22
 
23
  # Perform the prediction
24
  prediction = model.predict(input_data)
25
 
26
+ return f"The predicted house price is ${prediction[0]:,.2f}"
27
 
28
  # Create the Gradio interface
29
  interface = gr.Interface(
30
  fn=predict,
31
  inputs=[
32
+ gr.Dropdown(choices=list(neighborhood_values), label="Neighborhood"),
33
+ gr.Textbox(label="House Size (in square feet)"),
34
+ gr.Textbox(label="Number of Rooms")
 
35
  ],
36
  outputs="text",
37
+ title="House Price Predictor",
38
+ description="Enter the neighborhood, house size, and number of rooms to predict the house price."
39
  )
40
 
41
+
42
+
43
  # Launch the app
44
+ interface.launch()