Aliou12 commited on
Commit
aeae2d5
·
1 Parent(s): 6f6d525

mettre a jours

Browse files
Files changed (1) hide show
  1. app.py +68 -9
app.py CHANGED
@@ -9,7 +9,7 @@ try:
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}
@@ -34,8 +34,41 @@ def predict_price(kms_driven, present_price, fuel_type, seller_type, transmissio
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"),
@@ -43,13 +76,39 @@ input_labels = [
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
 
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 simple
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}
 
34
  except Exception as e:
35
  return f"Erreur lors de la prédiction : {str(e)}"
36
 
37
+ # Fonction de prédiction multiple
38
+ def predict_multiple(inputs):
39
+ # Encodage des variables catégoriques
40
+ fuel_type_mapping = {"Petrol": 0, "Diesel": 1, "CNG": 2}
41
+ seller_type_mapping = {"Dealer": 0, "Individual": 1}
42
+ transmission_mapping = {"Manual": 0, "Automatic": 1}
43
+
44
+ predictions = []
45
+
46
+ try:
47
+ for entry in inputs:
48
+ kms_driven, present_price, fuel_type, seller_type, transmission, age = entry
49
+
50
+ # Conversion des types et gestion des encodages
51
+ fuel_type = fuel_type_mapping.get(fuel_type, -1)
52
+ seller_type = seller_type_mapping.get(seller_type, -1)
53
+ transmission = transmission_mapping.get(transmission, -1)
54
+
55
+ if fuel_type == -1 or seller_type == -1 or transmission == -1:
56
+ predictions.append("Erreur : Valeurs non reconnues pour les types de carburant, vendeur ou transmission.")
57
+ continue
58
+
59
+ # Création de l'entrée pour le modèle
60
+ features = np.array([kms_driven, present_price, fuel_type, seller_type, transmission, age]).reshape(1, -1)
61
+
62
+ # Prédiction
63
+ prediction = lr.predict(features)[0]
64
+ predictions.append(round(prediction, 2))
65
+
66
+ return predictions
67
+ except Exception as e:
68
+ return [f"Erreur lors de la prédiction : {str(e)}"]
69
+
70
+ # Interface Gradio pour la prédiction simple
71
+ simple_input_labels = [
72
  gr.Number(label="Kms_Driven"),
73
  gr.Number(label="Present_Price"),
74
  gr.Dropdown(choices=["Petrol", "Diesel", "CNG"], label="Fuel_Type"),
 
76
  gr.Dropdown(choices=["Manual", "Automatic"], label="Transmission"),
77
  gr.Number(label="Age"),
78
  ]
79
+ simple_output = gr.Number(label="Predicted Price")
80
+
81
+ # Interface Gradio pour la prédiction multiple
82
+ multiple_input_labels = [
83
+ gr.Dataframe(
84
+ headers=["Kms_Driven", "Present_Price", "Fuel_Type", "Seller_Type", "Transmission", "Age"],
85
+ datatype=["number", "number", "str", "str", "str", "number"],
86
+ row_count=3,
87
+ col_count=6,
88
+ label="Entrées multiples",
89
+ )
90
+ ]
91
+ multiple_output = gr.Dataframe(label="Prédictions", headers=["Predicted Price"])
92
 
93
+ # Interface combinée
94
+ interface = gr.TabbedInterface(
95
+ [
96
+ gr.Interface(
97
+ fn=predict_price,
98
+ inputs=simple_input_labels,
99
+ outputs=simple_output,
100
+ title="Car Price Prediction (Simple)",
101
+ description="Prédisez le prix d'une voiture en entrant une seule série de caractéristiques.",
102
+ ),
103
+ gr.Interface(
104
+ fn=predict_multiple,
105
+ inputs=multiple_input_labels,
106
+ outputs=multiple_output,
107
+ title="Car Price Prediction (Multiple)",
108
+ description="Prédisez les prix pour plusieurs voitures en entrant plusieurs séries de caractéristiques.",
109
+ ),
110
+ ],
111
+ tab_names=["Prédiction Simple", "Prédiction Multiple"]
112
  )
113
 
114
  # Lancer l'application