vishurdx commited on
Commit
d40d071
·
verified ·
1 Parent(s): e312951

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +20 -0
  2. app.py +35 -0
  3. delivery_time_model.pkl +3 -0
  4. requirements.txt +12 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Python runtime as a parent image
2
+ FROM python:3.9-slim
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /code
6
+
7
+ # Copy the requirements file into the container at /code
8
+ COPY ./requirements.txt /code/requirements.txt
9
+
10
+ # Install any needed packages specified in requirements.txt
11
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
12
+
13
+ # Copy the rest of the application's code from the current directory to /code
14
+ COPY . /code/
15
+
16
+ # Expose the port the app runs on (Hugging Face uses 7860)
17
+ EXPOSE 7860
18
+
19
+ # Command to run the app using uvicorn
20
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.responses import JSONResponse
3
+ from pydantic import BaseModel, Field, computed_field
4
+ import numpy as np
5
+ from typing import Literal, Annotated
6
+ import pickle
7
+ import math
8
+ import pandas as pd
9
+
10
+ # import the ML model
11
+ with open('delivery_time_model.pkl','rb') as f:
12
+ model = pickle.load(f)
13
+
14
+ app = FastAPI()
15
+
16
+
17
+ # pydantic model build to validate the input data
18
+
19
+ class UserInput(BaseModel):
20
+ age : Annotated[int,Field(...,ge = 18, lt = 120,description = 'Age of the delivery person')]
21
+ rating : Annotated[float,Field(...,ge = 1, le = 6 ,description = 'Delivery person Ratings')]
22
+ distance : Annotated[int,Field(...,gt = 0,description = 'Total Distance to be covered')]
23
+
24
+
25
+ @app.post('/predict')
26
+ def predict_time(data: UserInput):
27
+ features = np.array([[data.age, data.rating, data.distance]])
28
+ prediction = model.predict(features)
29
+
30
+ prediction_value = math.ceil(float(prediction[0]))
31
+
32
+ return JSONResponse(
33
+ status_code=200,
34
+ content={"Predicted Delivery Time in Minutes": prediction_value}
35
+ )
delivery_time_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:951d09ab2ad27f612dcb8846718ce182f9412e597b4fd98d8cf345640a1432d4
3
+ size 1449096
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Libraries for FastAPI Backend
2
+ fastapi
3
+ uvicorn
4
+ pydantic
5
+ numpy
6
+ scikit-learn
7
+ pandas
8
+ tensorflow
9
+ keras
10
+ # Libraries for Streamlit Frontend
11
+ streamlit
12
+ requests