Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- Dockerfile +5 -9
- app.py +40 -38
- requirements.txt +9 -1
Dockerfile
CHANGED
|
@@ -1,16 +1,12 @@
|
|
| 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 on the host to the container's /app directory
|
| 8 |
COPY . .
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
# Define the command to run the Streamlit app on port 8501 and make it accessible externally
|
| 14 |
-
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
| 15 |
|
| 16 |
-
# NOTE: Disable XSRF protection for easier external access in order to make batch predictions
|
|
|
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
|
|
|
|
|
|
| 4 |
COPY . .
|
| 5 |
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
EXPOSE 7860
|
| 9 |
+
|
| 10 |
+
CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:7860", "app:superkart_api"]
|
| 11 |
|
|
|
|
|
|
|
| 12 |
|
|
|
app.py
CHANGED
|
@@ -1,39 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
else:
|
| 39 |
-
st.error("Error in API request")
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from flask import Flask, request, jsonify
|
| 5 |
|
| 6 |
+
# Create Flask app
|
| 7 |
+
superkart_api = Flask(__name__)
|
| 8 |
+
|
| 9 |
+
# Load the trained model
|
| 10 |
+
model = joblib.load("tuned_gradient_boosting_regressor_model.joblib")
|
| 11 |
+
|
| 12 |
+
@superkart_api.get('/')
|
| 13 |
+
def home():
|
| 14 |
+
return "Welcome to the Superkart Sales Prediction API!"
|
| 15 |
+
|
| 16 |
+
@superkart_api.post('/v1/predict')
|
| 17 |
+
def predict_sales():
|
| 18 |
+
data = request.get_json()
|
| 19 |
+
|
| 20 |
+
sample = {
|
| 21 |
+
'Product_Weight': data['Product_Weight'],
|
| 22 |
+
'Product_Sugar_Content': data['Product_Sugar_Content'],
|
| 23 |
+
'Product_Allocated_Area': data['Product_Allocated_Area'],
|
| 24 |
+
'Product_MRP': data['Product_MRP'],
|
| 25 |
+
'Store_Size': data['Store_Size'],
|
| 26 |
+
'Store_Location_City_Type': data['Store_Location_City_Type'],
|
| 27 |
+
'Store_Type': data['Store_Type'],
|
| 28 |
+
'Product_Id_char': data['Product_Id_char'],
|
| 29 |
+
'Store_Age_Years': data['Store_Age_Years'],
|
| 30 |
+
'Product_Type_Category': data['Product_Type_Category']
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
input_df = pd.DataFrame([sample])
|
| 34 |
+
prediction = model.predict(input_df).tolist()[0]
|
| 35 |
+
|
| 36 |
+
return jsonify({'Sales': prediction})
|
| 37 |
+
|
| 38 |
+
if __name__ == '__main__':
|
| 39 |
+
import os
|
| 40 |
+
port = int(os.environ.get("PORT", 7860))
|
| 41 |
+
superkart_api.run(host="0.0.0.0", port=port)
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
requests==2.32.3
|
| 2 |
-
streamlit==1.45.0
|
|
|
|
| 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 |
+
Werkzeug==2.2.2
|
| 8 |
+
flask==2.2.2
|
| 9 |
+
gunicorn==20.1.0
|
| 10 |
requests==2.32.3
|
|
|