Upload folder using huggingface_hub
Browse files- Dockerfile +17 -0
- app.py +54 -0
- requirements.txt +12 -0
Dockerfile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a minimal base image with Python 3.9 installed
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
+
|
| 4 |
+
# Set the working directory inside the container to /app
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy all files from the current directory to the container's working directory
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
# Install dependencies from the requirements file without using cache to reduce image size
|
| 11 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Define the command to start the application using Gunicorn with 4 worker processes
|
| 14 |
+
# - `-w 4`: Uses 4 worker processes for handling requests
|
| 15 |
+
# - `-b 0.0.0.0:7860`: Binds the server to port 7860 on all network interfaces
|
| 16 |
+
# - `app:app`: Runs the Flask app (assuming `app.py` contains the Flask instance named `app`)
|
| 17 |
+
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:SuperKart_predictor_api"]
|
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from flask import Flask, request, jsonify
|
| 5 |
+
|
| 6 |
+
# Initialize Flask app with a name
|
| 7 |
+
pred_mainteanance_api = Flask ("Engine Maintenance Predictor")
|
| 8 |
+
|
| 9 |
+
# Load the trained churn prediction model
|
| 10 |
+
model = joblib.load ("???.joblib")
|
| 11 |
+
|
| 12 |
+
# Define a route for the home page
|
| 13 |
+
@pred_mainteanance_api.get ('/')
|
| 14 |
+
def home ():
|
| 15 |
+
return "Welcome to the Engine Maintenance Prediction!"
|
| 16 |
+
|
| 17 |
+
# Define an endpoint to predict sales for Super Kart
|
| 18 |
+
@pred_mainteanance_api.post ('/v1/EngPredMaintenance')
|
| 19 |
+
def predict_need_maintenance ():
|
| 20 |
+
# Get JSON data from the request
|
| 21 |
+
engine_sensor_inputs = request.get_json ()
|
| 22 |
+
|
| 23 |
+
import datetime
|
| 24 |
+
|
| 25 |
+
current_year = datetime.datetime.now ().year # dynamic current year
|
| 26 |
+
|
| 27 |
+
# Extract relevant features from the input data
|
| 28 |
+
data_info = {
|
| 29 |
+
'Engine_rpm' : engine_sensor_inputs ['Engine_rpm'],
|
| 30 |
+
'Lub_oil_pressure' : engine_sensor_inputs ['Lub_oil_pressure'],
|
| 31 |
+
'Fuel_pressure' : engine_sensor_inputs ['Fuel_pressure'],
|
| 32 |
+
'Coolant_pressure' : engine_sensor_inputs ['Coolant_pressure'],
|
| 33 |
+
'lub_oil_temp' : engine_sensor_inputs ['lub_oil_temp'],
|
| 34 |
+
'Coolant_temp' : engine_sensor_inputs ['Coolant_temp']
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
# Convert the extracted data into a DataFrame
|
| 38 |
+
input_data = pd.DataFrame ([data_info])
|
| 39 |
+
|
| 40 |
+
# Enforce types - convert all to float
|
| 41 |
+
input_data = input_data.astype (float)
|
| 42 |
+
|
| 43 |
+
# Make prediction using the trained model
|
| 44 |
+
predicted_sales = model.predict (input_data).tolist ()[0]
|
| 45 |
+
|
| 46 |
+
# Return the prediction as a JSON response
|
| 47 |
+
return jsonify ({'NeedsMaintenance': predicted_sales})
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# Run the Flask app
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
import os
|
| 53 |
+
port = int (os.environ.get("PORT", 7860))
|
| 54 |
+
pred_mainteanance_api.run(host="0.0.0.0", port=port)
|
requirements.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
numpy==2.0.2
|
| 3 |
+
scikit-learn==1.6.1
|
| 4 |
+
xgboost==2.1.4
|
| 5 |
+
joblib==1.4.2
|
| 6 |
+
Werkzeug==2.2.2
|
| 7 |
+
flask==2.2.2
|
| 8 |
+
gunicorn==20.1.0
|
| 9 |
+
requests==2.28.1
|
| 10 |
+
uvicorn[standard]
|
| 11 |
+
streamlit==1.43.2
|
| 12 |
+
dill==0.3.8
|