new update
Browse files- .gitignore +1 -0
- app.py +41 -9
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.gradio/
|
app.py
CHANGED
@@ -4,21 +4,53 @@ import numpy as np
|
|
4 |
|
5 |
# Charger le modèle en spécifiant le chemin absolu
|
6 |
model_path = "./linear_regression_model.joblib"
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
# Fonction de prédiction
|
10 |
-
def predict_price(
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
output = gr.Number(label="Predicted Price")
|
20 |
|
21 |
-
interface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Lancer l'application
|
24 |
if __name__ == "__main__":
|
|
|
4 |
|
5 |
# Charger le modèle en spécifiant le chemin absolu
|
6 |
model_path = "./linear_regression_model.joblib"
|
7 |
+
try:
|
8 |
+
lr = joblib.load(model_path)
|
9 |
+
except FileNotFoundError:
|
10 |
+
raise FileNotFoundError(f"Le fichier modèle '{model_path}' est introuvable. Vérifiez le chemin.")
|
11 |
|
12 |
# Fonction de prédiction
|
13 |
+
def predict_price(kms_driven, present_price, fuel_type, seller_type, transmission, age):
|
14 |
+
# Encodage des variables catégoriques
|
15 |
+
fuel_type_mapping = {"Petrol": 0, "Diesel": 1, "CNG": 2}
|
16 |
+
seller_type_mapping = {"Dealer": 0, "Individual": 1}
|
17 |
+
transmission_mapping = {"Manual": 0, "Automatic": 1}
|
18 |
|
19 |
+
try:
|
20 |
+
# Conversion des types et gestion des encodages
|
21 |
+
fuel_type = fuel_type_mapping.get(fuel_type, -1)
|
22 |
+
seller_type = seller_type_mapping.get(seller_type, -1)
|
23 |
+
transmission = transmission_mapping.get(transmission, -1)
|
24 |
+
|
25 |
+
if fuel_type == -1 or seller_type == -1 or transmission == -1:
|
26 |
+
return "Erreur : Valeurs non reconnues pour les types de carburant, vendeur ou transmission."
|
27 |
+
|
28 |
+
# Création de l'entrée pour le modèle
|
29 |
+
features = np.array([kms_driven, present_price, fuel_type, seller_type, transmission, age]).reshape(1, -1)
|
30 |
|
31 |
+
# Prédiction
|
32 |
+
prediction = lr.predict(features)[0]
|
33 |
+
return round(prediction, 2)
|
34 |
+
except Exception as e:
|
35 |
+
return f"Erreur lors de la prédiction : {str(e)}"
|
36 |
+
|
37 |
+
# Interface Gradio
|
38 |
+
input_labels = [
|
39 |
+
gr.Number(label="Kms_Driven"),
|
40 |
+
gr.Number(label="Present_Price"),
|
41 |
+
gr.Dropdown(choices=["Petrol", "Diesel", "CNG"], label="Fuel_Type"),
|
42 |
+
gr.Dropdown(choices=["Dealer", "Individual"], label="Seller_Type"),
|
43 |
+
gr.Dropdown(choices=["Manual", "Automatic"], label="Transmission"),
|
44 |
+
gr.Number(label="Age"),
|
45 |
+
]
|
46 |
output = gr.Number(label="Predicted Price")
|
47 |
|
48 |
+
interface = gr.Interface(
|
49 |
+
fn=predict_price,
|
50 |
+
inputs=input_labels,
|
51 |
+
outputs=output,
|
52 |
+
title="Car Price Prediction"
|
53 |
+
)
|
54 |
|
55 |
# Lancer l'application
|
56 |
if __name__ == "__main__":
|