pradelf commited on
Commit
5e2fa16
·
1 Parent(s): 5889de4

Mise à jour des requêtes du web service de tarif

Browse files
Files changed (10) hide show
  1. Dockerfile +2 -0
  2. Dockerfile-local +24 -0
  3. README.md +6 -0
  4. app.py +18 -16
  5. build.sh +7 -0
  6. env.sh +24 -0
  7. requirements.txt +9 -6
  8. run.sh +10 -0
  9. secrets.sh +4 -0
  10. test/test.py +10 -0
Dockerfile CHANGED
@@ -18,3 +18,5 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt
18
 
19
  COPY --chown=user . /app
20
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
18
 
19
  COPY --chown=user . /app
20
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
21
+
22
+ #CMD ["bash","-lc","fastapi run app.py --host 0.0.0.0 --port ${PORT}"]
Dockerfile-local ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ ENV MLFLOW_EXPERIMENT_NAME=$MLFLOW_EXPERIMENT_NAME
4
+ ENV MLFLOW_TRACKING_URI=$MLFLOW_TRACKING_URI
5
+ ENV AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
6
+ ENV AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
7
+ ENV BACKEND_STORE_URI=$BACKEND_STORE_URI
8
+ ENV ARTIFACT_ROOT=$ARTIFACT_ROOT
9
+
10
+ ENV SPACE_URL=$SPACE_URL
11
+
12
+ RUN useradd -m -u 1000 user
13
+ USER user
14
+ ENV PATH="/home/user/.local/bin:$PATH"
15
+
16
+ WORKDIR /app
17
+
18
+ COPY --chown=user ./requirements.txt requirements.txt
19
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
20
+
21
+ COPY --chown=user . /app
22
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
23
+
24
+ #CMD ["bash","-lc","fastapi run app.py --host 0.0.0.0 --port ${PORT}"]
README.md CHANGED
@@ -8,4 +8,10 @@ pinned: false
8
  license: mit
9
  short_description: Web service for Getaround app to deliver car rental pricing
10
  ---
 
11
 
 
 
 
 
 
 
8
  license: mit
9
  short_description: Web service for Getaround app to deliver car rental pricing
10
  ---
11
+ # Web service for Getaround app
12
 
13
+ Bienvenue sur l'interface des web fonctions pour déterminer le prix de location de véhicule sur le projet Get Around de Jedha.
14
+
15
+ La documentation pour l'API se trouve sous le lien ci-dessous :
16
+
17
+ * [Web service for Getaround api](https://huggingface.co/spaces/pradelf/getaround-api/)
app.py CHANGED
@@ -65,6 +65,7 @@ app = FastAPI(
65
 
66
 
67
  class RentalFeatures(BaseModel):
 
68
  model_key: str
69
  mileage: int
70
  engine_power: int
@@ -102,22 +103,23 @@ async def predict(predictionFeatures: RentalFeatures):
102
  Prediction of car daily rental cost for a given properties of a car !
103
  """
104
  # Read data
105
- pf = [
106
- predictionFeatures.model_key or "Peugeot",
107
- predictionFeatures.mileage or 0,
108
- predictionFeatures.engine_power or 0,
109
- predictionFeatures.fuel or "petrol",
110
- predictionFeatures.car_type or "sedan",
111
- predictionFeatures.private_parking_available or 1,
112
- predictionFeatures.has_gps or 0,
113
- predictionFeatures.has_air_conditioning or 0,
114
- predictionFeatures.automatic_car or 0,
115
- predictionFeatures.has_getaround_connect or 0,
116
- predictionFeatures.has_speed_regulator or 0,
117
- predictionFeatures.winter_tires or 0,
118
- ]
119
-
120
- car_caracteristic = pd.DataFrame({"Car": pf})
 
121
 
122
  # Log model from mlflow
123
  logged_model = "models:/getaround-price-prediction-model/versions/2" # REPLACE WITH YOUR OWN RUN ID
 
65
 
66
 
67
  class RentalFeatures(BaseModel):
68
+ model_key: str
69
  model_key: str
70
  mileage: int
71
  engine_power: int
 
103
  Prediction of car daily rental cost for a given properties of a car !
104
  """
105
  # Read data
106
+ # pf = [
107
+ # predictionFeatures.model_key or "Peugeot",
108
+ # predictionFeatures.mileage or 0,
109
+ # predictionFeatures.engine_power or 0,
110
+ # predictionFeatures.fuel or "petrol",
111
+ # predictionFeatures.car_type or "sedan",
112
+ # predictionFeatures.private_parking_available or 1,
113
+ # predictionFeatures.has_gps or 0,
114
+ # predictionFeatures.has_air_conditioning or 0,
115
+ # predictionFeatures.automatic_car or 0,
116
+ # predictionFeatures.has_getaround_connect or 0,
117
+ # predictionFeatures.has_speed_regulator or 0,
118
+ # predictionFeatures.winter_tires or 0,
119
+ # ]
120
+
121
+ car_caracteristic = pd.DataFrame([predictionFeatures.model_dump()])
122
+ #car_caracteristic = pd.DataFrame({"Car": pf})
123
 
124
  # Log model from mlflow
125
  logged_model = "models:/getaround-price-prediction-model/versions/2" # REPLACE WITH YOUR OWN RUN ID
build.sh ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ set -e
4
+ echo 'Build docker image for Get Around API.'
5
+ source env.sh
6
+ echo $IMAGE_ID
7
+ docker build -f Dockerfile-local -t $IMAGE_ID --no-cache .
env.sh ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+
4
+ export MLFLOW_EXPERIMENT_NAME=
5
+
6
+ export MLFLOW_TRACKING_URI=
7
+
8
+ export BACKEND_STORE_URI=
9
+
10
+ export SPACE_URL = "https://pradelf-getaround-api.hf.space"
11
+
12
+ export ARTIFACT_ROOT=
13
+
14
+ export APP_NAME="getaround-api"
15
+
16
+ export REPOSITORY_TAG_URI="$APP_NAME"
17
+
18
+ export TAG="0.0.1"
19
+
20
+ export TAGNAME="certification"
21
+
22
+ export IMAGE_APP_ID="$REPOSITORY_TAG_URI:$TAGNAME"
23
+
24
+ export $(grep -v '^#' .env | xargs -d '\n')
requirements.txt CHANGED
@@ -1,7 +1,10 @@
1
- fastapi
2
  uvicorn[standard]
3
- pydantic
4
- mlflow
5
- pandas
6
-
7
-
 
 
 
 
1
+ fastapi[standard]
2
  uvicorn[standard]
3
+ pydantic
4
+ typing
5
+ pandas
6
+ openpyxl
7
+ mlflow
8
+ scikit-learn
9
+ python-multipart
10
+ fsspec
run.sh ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ docker run -it \
2
+ -v "$(pwd):/home/app" \
3
+ -p 7860:7860 \
4
+ -e PORT=7860 \
5
+ -e MLFLOW_TRACKING_URI=$MLFLOW_TRACKING_URI \
6
+ -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
7
+ -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
8
+ -e BACKEND_STORE_URI=$BACKEND_STORE_URI \
9
+ -e ARTIFACT_ROOT=$ARTIFACT_ROOT \
10
+ api
secrets.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ export MLFLOW_EXPERIMENT_NAME="salary_estimator";
2
+ export MLFLOW_TRACKING_URI="MLFLOW_TRACKING_URI";
3
+ export BACKEND_STORE_URI="BACKEND_STORE_URI";
4
+ export ARTIFACT_ROOT="ARTIFACT_ROOT";
test/test.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ payload = {
3
+ "title": "This is my great blog title",
4
+ "content": "This is the body of my article",
5
+ "Author": "Jaskier"
6
+ }
7
+ r = requests.post("http://localhost:7860/predict", json={
8
+ "YearsExperience": 0
9
+ })
10
+ print(r.content)