|
|
|
import gradio as gr |
|
import numpy as np |
|
import pandas as pd |
|
import tensorflow as tf |
|
|
|
|
|
model = tf.keras.models.load_model('real_estate_price_prediction_model.h5') |
|
|
|
|
|
original_df = pd.read_excel('/content/Moroccan Real Estate Price Clean Dataset .xlsx') |
|
|
|
|
|
unique_secteurs = original_df['secteur'].unique() |
|
unique_cities = original_df['city'].unique() |
|
|
|
|
|
columns = ['surface', 'pieces', 'chambres', 'sdb', 'age', 'etage', 'etat_Bon état', 'etat_Nouveau', 'etat_À rénover', 'secteur', 'city'] |
|
|
|
|
|
def preprocess_input(user_input, columns, unique_secteurs, unique_cities): |
|
|
|
total_features = 1015 |
|
|
|
|
|
input_array = np.zeros((1, total_features), dtype=np.float64) |
|
|
|
|
|
numerical_features = ['surface', 'pieces', 'chambres', 'sdb', 'age', 'etage', 'etat_Bon état', 'etat_Nouveau', 'etat_À rénover'] |
|
for feature in numerical_features: |
|
input_array[0, columns.index(feature)] = user_input[feature] |
|
|
|
|
|
for feature in ['secteur', 'city']: |
|
if user_input[feature] in unique_secteurs or user_input[feature] in unique_cities: |
|
input_array[0, columns.index(user_input[feature])] = 1 |
|
|
|
return input_array |
|
|
|
|
|
def predict_price(user_input): |
|
|
|
input_array = preprocess_input(user_input, columns, unique_secteurs, unique_cities) |
|
|
|
|
|
predicted_price = model.predict(input_array) |
|
|
|
return predicted_price[0][0] |
|
|
|
|
|
interface = gr.Interface( |
|
fn=predict_price, |
|
inputs=[ |
|
gr.Slider(label=f"Enter value for 'surface'", minimum=0, maximum=500, step=1), |
|
gr.Slider(label=f"Enter value for 'pieces'", minimum=0, maximum=15, step=1), |
|
gr.Slider(label=f"Enter value for 'chambres'", minimum=0, maximum=10, step=1), |
|
gr.Slider(label=f"Enter value for 'sdb'", minimum=0, maximum=5, step=1), |
|
gr.Slider(label=f"Enter value for 'age'", minimum=0, maximum=115, step=1), |
|
gr.Slider(label=f"Enter value for 'etage'", minimum=0, maximum=20, step=1), |
|
gr.Slider(label=f"Enter value for 'etat_Bon état'", minimum=0, maximum=1, step=1), |
|
gr.Slider(label=f"Enter value for 'etat_Nouveau'", minimum=0, maximum=1, step=1), |
|
gr.Slider(label=f"Enter value for 'etat_À rénover'", minimum=0, maximum=1, step=1), |
|
gr.Textbox(label=f"Enter value for 'secteur'", type="text"), |
|
gr.Textbox(label=f"Enter value for 'city'", type="text") |
|
], |
|
outputs=gr.Textbox(label="Predicted Price:", interactive=False) |
|
) |
|
|
|
|
|
interface.launch(share=False, debug=False) |
|
|