Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile (1) +19 -0
- app (1).py +29 -0
- requirements (1).txt +7 -0
Dockerfile (1)
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Python base image
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy files
|
| 8 |
+
COPY requirements.txt .
|
| 9 |
+
COPY app.py .
|
| 10 |
+
COPY random_forest_pipeline.pkl .
|
| 11 |
+
|
| 12 |
+
# Install dependencies
|
| 13 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 14 |
+
|
| 15 |
+
# Expose port
|
| 16 |
+
EXPOSE 7860
|
| 17 |
+
|
| 18 |
+
# Run the Flask app
|
| 19 |
+
CMD ["python", "app.py"]
|
app (1).py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
# Load the trained SuperKart model
|
| 6 |
+
sales_model = joblib.load("random_forest_pipeline.pkl")
|
| 7 |
+
|
| 8 |
+
# Initialize Flask application
|
| 9 |
+
app = Flask(__name__)
|
| 10 |
+
|
| 11 |
+
# Root endpoint
|
| 12 |
+
@app.route('/')
|
| 13 |
+
def index():
|
| 14 |
+
return "SuperKart Sales Prediction Project"
|
| 15 |
+
|
| 16 |
+
# Prediction endpoint
|
| 17 |
+
@app.route('/predict', methods=['POST'])
|
| 18 |
+
def make_prediction():
|
| 19 |
+
try:
|
| 20 |
+
input_data = request.get_json()
|
| 21 |
+
input_df = pd.DataFrame([input_data])
|
| 22 |
+
forecast = sales_model.predict(input_df)[0]
|
| 23 |
+
return jsonify({'Predicted_Sales_Product': round(forecast, 2)})
|
| 24 |
+
except Exception as err:
|
| 25 |
+
return jsonify({'error': str(err)})
|
| 26 |
+
|
| 27 |
+
# Launch the Flask server
|
| 28 |
+
if __name__ == '__main__':
|
| 29 |
+
app.run(host='0.0.0.0', port=7860)
|
requirements (1).txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
pandas
|
| 3 |
+
numpy
|
| 4 |
+
fastapi
|
| 5 |
+
uvicorn
|
| 6 |
+
joblib
|
| 7 |
+
scikit-learn==1.6.1
|