admattew commited on
Commit
133f7f5
·
verified ·
1 Parent(s): 3c696c5

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. Dockerfile +16 -0
  2. app.py +80 -0
  3. nozzle_selection.joblib +3 -0
  4. requirements.txt +15 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ # Set the working directory inside the container
4
+ WORKDIR /app
5
+
6
+ # Copy all files from the current directory to the container's working directory
7
+ COPY . .
8
+
9
+ # Install dependencies from the requirements file without using cache to reduce image size
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ # Define the command to start the application using Gunicorn with 4 worker processes
13
+ # - `-w 4`: Uses 4 worker processes for handling requests
14
+ # - `-b 0.0.0.0:7860`: Binds the server to port 7860 on all network interfaces
15
+ # - `app:app`: Runs the Flask app (assuming `app.py` contains the Flask instance named `app`)
16
+ CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:nozzleselect_api"]
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Import necessary libraries
3
+ import numpy as np
4
+ import joblib # For loading the serialized model
5
+ import pandas as pd # For data manipulation
6
+ from flask import Flask, request, jsonify # For creating the Flask API
7
+
8
+ # Initialize Flask app with a name
9
+ superkart_api = Flask("ABMs Nozzle Selection By AFWC Passing Pressure") #define the name of the app
10
+
11
+ # Load the trained prediction model
12
+ model = joblib.load("nozzle_selection.joblib") #define the location of the serialized model
13
+
14
+ # Define a route for the home page
15
+ @superkart_api.get('/')
16
+ def home():
17
+ """
18
+ This function handles GET requests to the root URL ('/') of the API.
19
+ It returns a simple welcome message.
20
+ """
21
+ return "Welcome to Babatunde's AFWC Nozzle Selection Predictor API!" #define a welcome message
22
+
23
+ # Define an endpoint to predict churn for a single customer
24
+ @nozzleselect_api.post('/v1/predict')
25
+ def predict_nozzle():
26
+ """
27
+ This function handles POST requests to the '/v1/predict' endpoint.
28
+ It expects a JSON payload containing property details and returns
29
+ the predicted sales outcome price as a JSON response.
30
+ """
31
+ # Get JSON data from the request
32
+ data = request.get_json()
33
+
34
+ # Extract relevant product ans store features from the input data. The order of the column names matters.
35
+ sample = {
36
+ 'Coat Grid1': data['cg'],
37
+ 'Coat Grid1 Flux Weight': data['cg_fw'],
38
+ 'Coat Grid2': data['cg'],
39
+ 'Coat Grid2 Flux Weight': data['cg_fw'],
40
+ 'Pressure': data['pressure'],
41
+
42
+ }
43
+
44
+
45
+ # Convert the extracted data into a DataFrame
46
+ input_data = pd.DataFrame([sample])
47
+
48
+ # Make a sales prediction using the trained model
49
+ prediction = model.predict(input_data).tolist()[0]
50
+
51
+ # Return the prediction as a JSON response
52
+ return jsonify({'Nozzle': prediction})
53
+
54
+ # Define an endpoint for batch prediction (POST request)
55
+ @nozzleselect_api.post('/v1/predictbatch')
56
+
57
+ """
58
+ def predict_sales_batch():
59
+ """
60
+ This function handles POST requests to the '/v1/predictbatch' endpoint.
61
+ It expects a CSV file containing property details for multiple properties
62
+ and returns the predicted rental prices as a dictionary in the JSON response.
63
+ """
64
+ # Get the uploaded CSV file from the request
65
+ file = request.files['file']
66
+
67
+ # Read the CSV file into a Pandas DataFrame
68
+ input_data = pd.read_csv(file)
69
+
70
+ # Make predictions for all properties in the DataFrame
71
+ predicted_sales = model.predict(input_data).tolist()
72
+
73
+ # Return the prediction as a JSON response
74
+ return jsonify({'Sales': predicted_sales})
75
+
76
+ """
77
+
78
+ # Run the Flask app in debug mode
79
+ if __name__ == '__main__':
80
+ nozzleselect_api.run(debug=True)
nozzle_selection.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e01b8ef8be7c88fd6393ae6c8ac11ea204cfe445ae48d1bbc006e93606294ca
3
+ size 431004
requirements.txt ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pandas==2.2.2
2
+ numpy==2.0.2
3
+ scikit-learn==1.6.1
4
+ seaborn==0.13.2
5
+ joblib==1.4.2
6
+ xgboost==2.1.4
7
+ joblib==1.4.2
8
+ Werkzeug==2.2.2
9
+ flask==2.2.2
10
+ gunicorn==20.1.0
11
+ requests==2.32.3
12
+ uvicorn[standard]
13
+ streamlit==1.43.2
14
+ huggingface_hub==0.20.3
15
+ hf_xet