Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- Requierement.txt +4 -0
- app.py +62 -0
- lasso_model.joblib +3 -0
- sample_data.csv +11 -0
Requierement.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pandas
|
| 3 |
+
scikit-learn
|
| 4 |
+
joblib
|
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from joblib import load
|
| 4 |
+
|
| 5 |
+
# Charger le modèle sauvegardé
|
| 6 |
+
model = load('lasso_model.joblib')
|
| 7 |
+
|
| 8 |
+
# Fonction pour prédire une seule observation
|
| 9 |
+
def predict_single(Kms_Driven, Present_Price, Fuel_Type, Seller_Type, Transmission, Age):
|
| 10 |
+
# Créer les features en fonction des colonnes nécessaires au modèle
|
| 11 |
+
features = [[Kms_Driven, Present_Price, Fuel_Type, Seller_Type, Transmission, Age]]
|
| 12 |
+
# Prédire avec le modèle
|
| 13 |
+
prediction = model.predict(features)
|
| 14 |
+
return prediction[0] # Retourner la prédiction
|
| 15 |
+
|
| 16 |
+
# Fonction pour prédire plusieurs observations à partir d'un fichier CSV
|
| 17 |
+
def predict_multiple(file):
|
| 18 |
+
# Charger le fichier CSV
|
| 19 |
+
data = pd.read_csv(file)
|
| 20 |
+
# Vérifier si les colonnes nécessaires sont présentes dans le fichier
|
| 21 |
+
required_columns = ['Kms_Driven', 'Present_Price', 'Fuel_Type', 'Seller_Type', 'Transmission', 'Age']
|
| 22 |
+
if not all(col in data.columns for col in required_columns):
|
| 23 |
+
return f"Le fichier CSV doit contenir les colonnes suivantes : {', '.join(required_columns)}"
|
| 24 |
+
# Prédire les résultats
|
| 25 |
+
predictions = model.predict(data[required_columns])
|
| 26 |
+
data['Prediction'] = predictions
|
| 27 |
+
return data # Retourner le DataFrame avec les prédictions ajoutées
|
| 28 |
+
|
| 29 |
+
# Interface Gradio
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("### Prédictions avec le Modèle Lasso")
|
| 32 |
+
|
| 33 |
+
# Interface pour une prédiction unique
|
| 34 |
+
with gr.Tab("Prédiction Unique"):
|
| 35 |
+
Kms_Driven = gr.Number(label="Kilométrage (Kms Driven)")
|
| 36 |
+
Present_Price = gr.Number(label="Prix Actuel (Present Price)")
|
| 37 |
+
Fuel_Type = gr.Number(label="Type de Carburant (Fuel Type)")
|
| 38 |
+
Seller_Type = gr.Number(label="Type de Vendeur (Seller Type)")
|
| 39 |
+
Transmission = gr.Number(label="Transmission (Manuelle=0, Automatique=1)")
|
| 40 |
+
Age = gr.Number(label="Âge du Véhicule")
|
| 41 |
+
predict_btn = gr.Button("Prédire")
|
| 42 |
+
output = gr.Textbox(label="Résultat")
|
| 43 |
+
predict_btn.click(
|
| 44 |
+
predict_single,
|
| 45 |
+
inputs=[Kms_Driven, Present_Price, Fuel_Type, Seller_Type, Transmission, Age],
|
| 46 |
+
outputs=output
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
# Interface pour prédictions multiples à partir d'un fichier CSV
|
| 50 |
+
with gr.Tab("Prédiction Multiple"):
|
| 51 |
+
file_input = gr.File(label="Uploader un fichier CSV")
|
| 52 |
+
output_file = gr.DataFrame(label="Résultats avec Prédictions")
|
| 53 |
+
predict_btn_csv = gr.Button("Prédire pour le CSV")
|
| 54 |
+
predict_btn_csv.click(
|
| 55 |
+
predict_multiple,
|
| 56 |
+
inputs=file_input,
|
| 57 |
+
outputs=output_file
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# Lancer l'application
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
demo.launch()
|
lasso_model.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aec6283cf6ddb2f25cdf13e73777c06c7f89d812499f5f6e9e0fdf11af02154c
|
| 3 |
+
size 679
|
sample_data.csv
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Kms_Driven,Present_Price,Fuel_Type,Seller_Type,Transmission,Age
|
| 2 |
+
27000,5.59,2,0,1,6
|
| 3 |
+
43000,9.54,1,0,1,7
|
| 4 |
+
6900,9.85,2,0,1,3
|
| 5 |
+
5200,4.15,2,0,1,9
|
| 6 |
+
42450,6.87,1,0,1,6
|
| 7 |
+
2071,9.83,1,0,1,2
|
| 8 |
+
18796,8.12,2,0,1,5
|
| 9 |
+
33429,8.61,1,0,1,5
|
| 10 |
+
20273,8.89,1,0,1,4
|
| 11 |
+
42367,8.92,1,0,1,5
|