Update app.py
Browse files
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 |
-
|
| 10 |
|
| 11 |
# Define the prediction function
|
| 12 |
-
def predict(
|
| 13 |
# Convert inputs to appropriate types
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
resolution_height = int(resolution_height)
|
| 17 |
|
| 18 |
# Prepare the input array for prediction
|
| 19 |
input_data = pd.DataFrame({
|
| 20 |
-
'
|
| 21 |
-
'
|
| 22 |
-
'
|
| 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(
|
| 36 |
-
gr.Textbox(label="
|
| 37 |
-
gr.Textbox(label="
|
| 38 |
-
gr.Textbox(label="Resolution (Height)")
|
| 39 |
],
|
| 40 |
outputs="text",
|
| 41 |
-
title="
|
| 42 |
-
description="Enter the
|
| 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()
|