Upload folder using huggingface_hub
Browse files- Dockerfile +24 -0
- app.py +52 -0
- final_model.joblib +3 -0
- preprocessor.joblib +3 -0
- requirements.txt +7 -0
Dockerfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a lightweight official Python image
|
| 2 |
+
FROM python:3.9-slim-buster
|
| 3 |
+
|
| 4 |
+
# Set the working directory inside the container
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy the requirements file and install dependencies
|
| 8 |
+
COPY requirements.txt .
|
| 9 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 10 |
+
|
| 11 |
+
# Copy the application files
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
# Expose the port the Flask app will run on
|
| 15 |
+
#EXPOSE 7860
|
| 16 |
+
|
| 17 |
+
# Command to run the Flask application
|
| 18 |
+
#CMD ["python", "app.py"]
|
| 19 |
+
|
| 20 |
+
# Define the command to start the application using Gunicorn with 4 worker processes
|
| 21 |
+
# - `-w 4`: Uses 4 worker processes for handling requests
|
| 22 |
+
# - `-b 0.0.0.0:7860`: Binds the server to port 7860 on all network interfaces
|
| 23 |
+
# - `app:app`: Runs the Flask app (assuming `app.py` contains the Flask instance named `app`)
|
| 24 |
+
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:superkart_revenue_forecaster_api"]
|
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import joblib
|
| 3 |
+
from flask import Flask, request, jsonify
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# Load the trained model and preprocessor
|
| 8 |
+
model = joblib.load('final_model.joblib')
|
| 9 |
+
preprocessor = joblib.load('preprocessor.joblib')
|
| 10 |
+
|
| 11 |
+
superkart_revenue_forecaster_api = Flask("SuperKart Sales Revenue Forecaster")
|
| 12 |
+
|
| 13 |
+
# Define a route for the home page
|
| 14 |
+
@superkart_revenue_forecaster_api.get('/')
|
| 15 |
+
def home():
|
| 16 |
+
"""
|
| 17 |
+
This function handles GET requests to the root URL ('/') of the API.
|
| 18 |
+
It returns a simple welcome message.
|
| 19 |
+
"""
|
| 20 |
+
return 'Welcome to the SuperKart Revenue Forecaster - By Vidyasagar Chitchula!'
|
| 21 |
+
|
| 22 |
+
# Define the prediction route
|
| 23 |
+
@superkart_revenue_forecaster_api.route('/forecast_revenue', methods=['POST'])
|
| 24 |
+
def forecast_Revenue():
|
| 25 |
+
try:
|
| 26 |
+
data = request.get_json()
|
| 27 |
+
|
| 28 |
+
# Convert input data to a Pandas DataFrame
|
| 29 |
+
input_df = pd.DataFrame([data])
|
| 30 |
+
|
| 31 |
+
# Recreate the 'Store_Age' feature if 'Store_Establishment_Year' is provided
|
| 32 |
+
if 'Store_Establishment_Year' in input_df.columns:
|
| 33 |
+
input_df['Store_Age'] = 2025 - input_df['Store_Establishment_Year']
|
| 34 |
+
input_df = input_df.drop('Store_Establishment_Year', axis=1)
|
| 35 |
+
|
| 36 |
+
# Drop 'Product_Id' if it exists in the input
|
| 37 |
+
if 'Product_Id' in input_df.columns:
|
| 38 |
+
input_df = input_df.drop('Product_Id', axis=1)
|
| 39 |
+
|
| 40 |
+
# Preprocess the input data
|
| 41 |
+
processed_data = preprocessor.transform(input_df)
|
| 42 |
+
|
| 43 |
+
# Make prediction
|
| 44 |
+
prediction = model.predict(processed_data)
|
| 45 |
+
|
| 46 |
+
return jsonify({'predicted_sales': prediction[0]})
|
| 47 |
+
|
| 48 |
+
except Exception as e:
|
| 49 |
+
return jsonify({'error': str(e)}), 400
|
| 50 |
+
|
| 51 |
+
if __name__ == '__main__':
|
| 52 |
+
superkart_revenue_forecaster_api.run(host='0.0.0.0', port=5000)
|
final_model.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4952cc0a10eaddb3114c051e637a29c35c2279b004a5b33a09fd25a5514778cc
|
| 3 |
+
size 485605
|
preprocessor.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:df5c9a62cdbbded3f573d4a2fc5f63903447b00652cec8c6d3210998bb161920
|
| 3 |
+
size 5118
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
joblib==1.4.2
|
| 3 |
+
pandas==2.2.2
|
| 4 |
+
numpy==2.0.2
|
| 5 |
+
scikit-learn==1.6.1
|
| 6 |
+
xgboost==2.1.4
|
| 7 |
+
requests==2.32.3
|