Upload folder using huggingface_hub
Browse files- Dockerfile +9 -9
- app.py +29 -37
- requirements.txt +8 -1
Dockerfile
CHANGED
|
@@ -1,16 +1,16 @@
|
|
| 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
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
-
# Copy all files from the current directory
|
| 8 |
COPY . .
|
| 9 |
|
| 10 |
-
# Install
|
| 11 |
-
RUN
|
| 12 |
|
| 13 |
-
# Define the command to
|
| 14 |
-
|
| 15 |
-
|
| 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 -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:app"]
|
app.py
CHANGED
|
@@ -1,43 +1,35 @@
|
|
| 1 |
-
import
|
| 2 |
import pandas as pd
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
st.write("This tool predicts next quarter sales for superkart. Enter the required information below.")
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
Store_Type = st.selectbox("Store_Type", ["Supermarket Type2", "Supermarket Type1","Departmental Store", "Food Mart"])
|
| 13 |
-
Store_Location_City_Type = st.selectbox("Store_Location_City_Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 14 |
-
Store_Establishment_Year = st.number_input("Store_Establishment_Year", min_value=1987, max_value=2009, step=1)
|
| 15 |
-
Product_Type = st.selectbox("Product_Type", ["Fruits and Vegetables", "Snack Foods", "Frozen Foods", "Dairy", "Household", "Baking Goods", "Canned", "Health and Hygiene", "Meat", "Soft Drinks", "Breads", "Hard Drinks", "Others", "Starchy Foods", "Breakfast", "Seafood"])
|
| 16 |
-
Product_Sugar_Content = st.selectbox("Product_Sugar_Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
|
| 17 |
-
Product_Weight = st.number_input("Product_Weight", min_value=4.0, max_value=22.0, step=1.0)
|
| 18 |
-
Product_Allocated_Area = st.number_input("Product_Allocated_Area", min_value=0.004, max_value=0.298, step=0.004)
|
| 19 |
-
Product_MRP = st.number_input("Product_MRP", min_value=31.0, value=226.0, step=1.0)
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
'Product_Sugar_Content': Product_Sugar_Content,
|
| 25 |
-
'Product_Weight': Product_Weight,
|
| 26 |
-
'Product_Allocated_Area': Product_Allocated_Area,
|
| 27 |
-
'Product_MRP': Product_MRP,
|
| 28 |
-
'Store_Id': Store_Id,
|
| 29 |
-
'Store_Size': Store_Size,
|
| 30 |
-
'Store_Type': Store_Type,
|
| 31 |
-
'Store_Location_City_Type': Store_Location_City_Type,
|
| 32 |
-
'Store_Establishment_Year': Store_Establishment_Year
|
| 33 |
-
}
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
st.write(f"Based on the information provided, the sales prediction is {sales_prediction}.")
|
| 42 |
-
else:
|
| 43 |
-
st.error("Error in API request")
|
|
|
|
| 1 |
+
import joblib
|
| 2 |
import pandas as pd
|
| 3 |
+
from flask import Flask, request, jsonify
|
| 4 |
|
| 5 |
+
app = Flask("Superkart Sales Predictor")
|
| 6 |
+
model = joblib.load("superkart.joblib")
|
|
|
|
| 7 |
|
| 8 |
+
@app.get('/')
|
| 9 |
+
def home():
|
| 10 |
+
return "Welcome to the Superkart Sales Predictor API"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
@app.post('/v1/sales')
|
| 13 |
+
def predict_sales():
|
| 14 |
+
product_data = request.get_json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
sample = {
|
| 17 |
+
'Product_Type': product_data['Product_Type'],
|
| 18 |
+
'Product_Sugar_Content': product_data['Product_Sugar_Content'],
|
| 19 |
+
'Product_Weight': product_data['Product_Weight'],
|
| 20 |
+
'Product_Allocated_Area': product_data['Product_Allocated_Area'],
|
| 21 |
+
'Product_MRP': product_data['Product_MRP'],
|
| 22 |
+
'Store_Id': product_data['Store_Id'],
|
| 23 |
+
'Store_Size': product_data['Store_Size'],
|
| 24 |
+
'Store_Type': product_data['Store_Type'],
|
| 25 |
+
'Store_Location_City_Type': product_data['Store_Location_City_Type'],
|
| 26 |
+
'Store_Establishment_Year': product_data['Store_Establishment_Year']
|
| 27 |
+
}
|
| 28 |
+
input_data = pd.DataFrame([sample])
|
| 29 |
+
input_data
|
| 30 |
|
| 31 |
+
prediction = model.predict(input_data).tolist()[0]
|
| 32 |
+
return jsonify({'prediction': prediction})
|
| 33 |
+
|
| 34 |
+
if __name__ == '__main__':
|
| 35 |
+
app.run(debug=True)
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,3 +1,10 @@
|
|
| 1 |
pandas==2.2.2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
requests==2.28.1
|
| 3 |
-
|
|
|
|
| 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]
|