Zbehel commited on
Commit
ab80adf
·
1 Parent(s): 62fce09

Ajouter openpyxl pour lire les fichiers Excel

Browse files
Files changed (5) hide show
  1. api.py +76 -0
  2. app.py +1 -1
  3. git_push.sh +5 -4
  4. requirements.txt +6 -4
  5. train.py +5 -1
api.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import mlflow
2
+ import uvicorn
3
+ import pandas as pd
4
+ from pydantic import BaseModel
5
+ from typing import Literal, List, Union
6
+ from fastapi import FastAPI, File, UploadFile
7
+ import joblib
8
+
9
+ # Log model from mlflow
10
+ logged_model = 'runs:/.../model'
11
+
12
+ # Load model as a PyFuncModel.
13
+ loaded_model = mlflow.pyfunc.load_model(logged_model)
14
+
15
+ tags_metadata = [
16
+ {
17
+ "name": "Machine Learning",
18
+ "description": "Prediction Endpoint."
19
+ }
20
+ ]
21
+
22
+ app = FastAPI(
23
+ title="Car price prediction API",
24
+ openapi_tags=tags_metadata
25
+ )
26
+
27
+ class PredictionFeatures(BaseModel):
28
+ model_key: str
29
+ mileage: int
30
+ engine_power: int
31
+ fuel: str
32
+ car_type: str
33
+ private_parking_available: bool
34
+ has_gps: bool
35
+ has_air_conditioning: bool
36
+ automatic_car: bool
37
+ has_getaround_connect: bool
38
+ has_speed_regulator: bool
39
+ winter_tires: bool
40
+
41
+ @app.get("/", tags=["Introduction Endpoints"])
42
+ async def index():
43
+ """
44
+ Simply returns a welcome message!
45
+ """
46
+ message = "Hello world! This `/` is the most simple and default endpoint. If you want to learn more, check out documentation of the api at `/docs`"
47
+ return message
48
+
49
+
50
+ @app.post("/predict", tags=["Machine Learning"])
51
+ async def predict(predictionFeatures: PredictionFeatures):
52
+ # Read data
53
+ input_data = pd.DataFrame({
54
+ "model_key": [predictionFeatures.model_key],
55
+ "mileage": [predictionFeatures.mileage],
56
+ "engine_power": [predictionFeatures.engine_power],
57
+ "fuel": [predictionFeatures.fuel],
58
+ "car_type": [predictionFeatures.car_type],
59
+ "private_parking_available": [predictionFeatures.private_parking_available],
60
+ "has_gps": [predictionFeatures.has_gps],
61
+ "has_air_conditioning": [predictionFeatures.has_air_conditioning],
62
+ "automatic_car": [predictionFeatures.automatic_car],
63
+ "has_getaround_connect": [predictionFeatures.has_getaround_connect],
64
+ "has_speed_regulator": [predictionFeatures.has_speed_regulator],
65
+ "winter_tires": [predictionFeatures.winter_tires]
66
+ })
67
+
68
+ prediction = loaded_model.predict(input_data)
69
+
70
+ # Format response
71
+ response = {"prediction": prediction.tolist()[0]}
72
+ return response
73
+
74
+
75
+ if __name__ == "__main__":
76
+ uvicorn.run(app, host="0.0.0.0", port=8000)
app.py CHANGED
@@ -3,7 +3,7 @@ import pandas as pd
3
  import plotly.express as px
4
 
5
  # Charger les données
6
- df = pd.read_csv('get_around_delay_analysis/rentals_data-Tableau 1.csv', sep=';')
7
 
8
  # Rename col time_delta_with_previous_rental_in_minutes & delay_at_checkout_in_minutes
9
  df.rename(columns={'time_delta_with_previous_rental_in_minutes': 'delta'}, inplace=True)
 
3
  import plotly.express as px
4
 
5
  # Charger les données
6
+ df = pd.read_excel('https://full-stack-assets.s3.eu-west-3.amazonaws.com/Deployment/get_around_delay_analysis.xlsx')
7
 
8
  # Rename col time_delta_with_previous_rental_in_minutes & delay_at_checkout_in_minutes
9
  df.rename(columns={'time_delta_with_previous_rental_in_minutes': 'delta'}, inplace=True)
git_push.sh CHANGED
@@ -3,15 +3,16 @@
3
  # Vérifiez si un message de commit a été fourni
4
  if [ -z "$1" ]
5
  then
6
- echo "Veuillez fournir un message de commit."
7
- exit 1
 
8
  fi
9
 
10
  # Ajouter tous les fichiers modifiés
11
  git add .
12
 
13
- # Commit avec le message fourni
14
- git commit -m "$1"
15
 
16
  # Pousser les modifications vers le dépôt distant
17
  git push origin main
 
3
  # Vérifiez si un message de commit a été fourni
4
  if [ -z "$1" ]
5
  then
6
+ COMMIT_MESSAGE="Debugging"
7
+ else
8
+ COMMIT_MESSAGE="$1"
9
  fi
10
 
11
  # Ajouter tous les fichiers modifiés
12
  git add .
13
 
14
+ # Commit avec le message fourni ou par défaut
15
+ git commit -m "$COMMIT_MESSAGE"
16
 
17
  # Pousser les modifications vers le dépôt distant
18
  git push origin main
requirements.txt CHANGED
@@ -1,7 +1,9 @@
1
  streamlit
2
- fastapi
3
- uvicorn
4
  pandas
5
  scikit-learn
6
- joblib
7
- mlflow
 
 
 
 
 
1
  streamlit
 
 
2
  pandas
3
  scikit-learn
4
+ mlflow
5
+ plotly
6
+ seaborn
7
+ matplotlib
8
+ boto3
9
+ openpyxl
train.py CHANGED
@@ -75,7 +75,11 @@ if __name__ == "__main__":
75
  # Print r2 score :
76
  model.score(X_test, y_test)
77
 
78
-
 
 
 
 
79
  print("...Done!")
80
  print("Saving model...")
81
  mlflow.sklearn.log_model(model, "model", signature=infer_signature(X_train, predictions))
 
75
  # Print r2 score :
76
  model.score(X_test, y_test)
77
 
78
+ # Enregistrer le run_id dans un fichier
79
+ run_id = run.info.run_id
80
+ with open("run_id.txt", "w") as f:
81
+ f.write(run_id)
82
+
83
  print("...Done!")
84
  print("Saving model...")
85
  mlflow.sklearn.log_model(model, "model", signature=infer_signature(X_train, predictions))