Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
import pandas as pd
|
@@ -7,10 +6,8 @@ import tensorflow as tf
|
|
7 |
# Load the trained model
|
8 |
model = tf.keras.models.load_model('real_estate_price_prediction_model.h5')
|
9 |
|
10 |
-
|
11 |
-
|
12 |
# Load the original dataset to get unique categories for 'secteur' and 'city'
|
13 |
-
original_df = pd.read_excel('Moroccan Real Estate Price Clean Dataset .xlsx') # Replace with your dataset path
|
14 |
|
15 |
# Get unique categories for 'secteur' and 'city'
|
16 |
unique_secteurs = original_df['secteur'].unique()
|
@@ -28,7 +25,7 @@ def preprocess_input(user_input, columns, unique_secteurs, unique_cities):
|
|
28 |
input_array = np.zeros((1, total_features), dtype=np.float64)
|
29 |
|
30 |
# Update numerical features
|
31 |
-
numerical_features = ['surface', 'pieces', 'chambres', 'sdb', 'age', 'etage', 'etat_Bon état', '
|
32 |
for feature in numerical_features:
|
33 |
input_array[0, columns.index(feature)] = user_input[feature]
|
34 |
|
@@ -40,14 +37,27 @@ def preprocess_input(user_input, columns, unique_secteurs, unique_cities):
|
|
40 |
return input_array
|
41 |
|
42 |
# Function to predict price based on user input
|
43 |
-
def predict_price(
|
44 |
# Preprocess the user input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
input_array = preprocess_input(user_input, columns, unique_secteurs, unique_cities)
|
46 |
|
47 |
# Make prediction using the model
|
48 |
predicted_price = model.predict(input_array)
|
49 |
|
50 |
-
return predicted_price[0][0]
|
51 |
|
52 |
# Gradio interface setup
|
53 |
interface = gr.Interface(
|
@@ -65,8 +75,8 @@ interface = gr.Interface(
|
|
65 |
gr.Textbox(label=f"Enter value for 'secteur'", type="text"),
|
66 |
gr.Textbox(label=f"Enter value for 'city'", type="text")
|
67 |
],
|
68 |
-
outputs=gr.Textbox(label="Predicted Price:", interactive=False)
|
69 |
)
|
70 |
|
71 |
# Launch the Gradio interface
|
72 |
-
interface.launch(share=False, debug=False)
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
|
|
6 |
# Load the trained model
|
7 |
model = tf.keras.models.load_model('real_estate_price_prediction_model.h5')
|
8 |
|
|
|
|
|
9 |
# Load the original dataset to get unique categories for 'secteur' and 'city'
|
10 |
+
original_df = pd.read_excel('/content/Moroccan Real Estate Price Clean Dataset .xlsx') # Replace with your dataset path
|
11 |
|
12 |
# Get unique categories for 'secteur' and 'city'
|
13 |
unique_secteurs = original_df['secteur'].unique()
|
|
|
25 |
input_array = np.zeros((1, total_features), dtype=np.float64)
|
26 |
|
27 |
# Update numerical features
|
28 |
+
numerical_features = ['surface', 'pieces', 'chambres', 'sdb', 'age', 'etage', 'etat_Bon état', 'etat_À rénover']
|
29 |
for feature in numerical_features:
|
30 |
input_array[0, columns.index(feature)] = user_input[feature]
|
31 |
|
|
|
37 |
return input_array
|
38 |
|
39 |
# Function to predict price based on user input
|
40 |
+
def predict_price(surface, pieces, chambres, sdb, age, etage, etat_Bon_état, etat_Nouveau, etat_À_rénover, secteur, city):
|
41 |
# Preprocess the user input
|
42 |
+
user_input = {
|
43 |
+
'surface': surface,
|
44 |
+
'pieces': pieces,
|
45 |
+
'chambres': chambres,
|
46 |
+
'sdb': sdb,
|
47 |
+
'age': age,
|
48 |
+
'etage': etage,
|
49 |
+
'etat_Bon état': etat_Bon_état,
|
50 |
+
'etat_Nouveau': etat_Nouveau,
|
51 |
+
'etat_À rénover': etat_À_rénover,
|
52 |
+
'secteur': secteur,
|
53 |
+
'city': city
|
54 |
+
}
|
55 |
input_array = preprocess_input(user_input, columns, unique_secteurs, unique_cities)
|
56 |
|
57 |
# Make prediction using the model
|
58 |
predicted_price = model.predict(input_array)
|
59 |
|
60 |
+
return f"Predicted price: {predicted_price[0][0]}"
|
61 |
|
62 |
# Gradio interface setup
|
63 |
interface = gr.Interface(
|
|
|
75 |
gr.Textbox(label=f"Enter value for 'secteur'", type="text"),
|
76 |
gr.Textbox(label=f"Enter value for 'city'", type="text")
|
77 |
],
|
78 |
+
outputs=gr.Textbox(label="Predicted Price(Dh):", interactive=False)
|
79 |
)
|
80 |
|
81 |
# Launch the Gradio interface
|
82 |
+
interface.launch(share=False, debug=False)
|