Upload folder using huggingface_hub
Browse files- Dockerfile +10 -11
- app.py +37 -50
- requirements.txt +1 -12
Dockerfile
CHANGED
|
@@ -1,16 +1,15 @@
|
|
| 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
|
| 7 |
-
COPY . .
|
| 8 |
|
| 9 |
-
# Install dependencies
|
| 10 |
-
RUN
|
| 11 |
|
| 12 |
-
# Define the command to
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
#
|
| 16 |
-
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:superkart_api"]
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
+
# Set the working directory inside the container to /app
|
| 4 |
+
WORKDIR /app
|
| 5 |
|
| 6 |
+
# Copy all files from the current directory on the host to the container's /app directory
|
| 7 |
+
COPY . .
|
| 8 |
|
| 9 |
+
# Install Python dependencies listed in requirements.txt
|
| 10 |
+
RUN pip3 install -r requirements.txt
|
| 11 |
|
| 12 |
+
# Define the command to run the Streamlit app on port 8501 and make it accessible externally
|
| 13 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
| 14 |
+
|
| 15 |
+
# NOTE: Disable XSRF protection for easier external access in order to make batch predictions
|
|
|
app.py
CHANGED
|
@@ -1,51 +1,38 @@
|
|
| 1 |
|
| 2 |
-
|
| 3 |
-
import
|
| 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 |
-
|
| 39 |
-
# Convert the extracted data into a DataFrame
|
| 40 |
-
input_data = pd.DataFrame([sample])
|
| 41 |
-
|
| 42 |
-
# Make a sales prediction using the trained model
|
| 43 |
-
prediction = model.predict(input_data).tolist()[0]
|
| 44 |
-
|
| 45 |
-
# Return the prediction as a JSON response
|
| 46 |
-
return jsonify({'Sales': prediction})
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
# Run the Flask app in debug mode
|
| 50 |
-
if __name__ == '__main__':
|
| 51 |
-
superkart_api.run(debug=True)
|
|
|
|
| 1 |
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
st.title("Superkart Prediction")
|
| 6 |
+
|
| 7 |
+
# Input fields for product and store data
|
| 8 |
+
Product_Weight = st.number_input("Product Weight", min_value=0.0, value=12.66)
|
| 9 |
+
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
|
| 10 |
+
Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.0, max_value=1.0, value=0.027)
|
| 11 |
+
Product_MRP = st.number_input("Product MRP", min_value=0.0, value=117.08)
|
| 12 |
+
Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1900, max_value=2026, value=2009)
|
| 13 |
+
Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 14 |
+
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 15 |
+
Store_Type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"])
|
| 16 |
+
Product_Type = st.selectbox("Product Type", ['Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene', 'Snack Foods', 'Soft Drinks', 'Household', 'Fruits and Vegetables', 'Meat', 'Hard Drinks', 'Breads', 'Breakfast', 'Starchy Foods', 'Seafood', 'Others'])
|
| 17 |
+
|
| 18 |
+
product_data = {
|
| 19 |
+
"Product_Weight": Product_Weight,
|
| 20 |
+
"Product_Sugar_Content": Product_Sugar_Content,
|
| 21 |
+
"Product_Allocated_Area": Product_Allocated_Area,
|
| 22 |
+
"Product_MRP": Product_MRP,
|
| 23 |
+
"Store_Establishment_Year": Store_Establishment_Year,
|
| 24 |
+
"Store_Size": Store_Size,
|
| 25 |
+
"Store_Location_City_Type": Store_Location_City_Type,
|
| 26 |
+
"Store_Type": Store_Type,
|
| 27 |
+
"Product_Type": Product_Type
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
if st.button("Predict", type='primary'):
|
| 31 |
+
# Replace 'ansarkar' with your Hugging Face username and 'superkart' with your backend space name
|
| 32 |
+
response = requests.post("https://ansarkar-superkart.hf.space/v1/predict", json=product_data)
|
| 33 |
+
if response.status_code == 200:
|
| 34 |
+
result = response.json()
|
| 35 |
+
predicted_sales = result["Sales"]
|
| 36 |
+
st.write(f"Predicted Product Store Sales Total: ₹{predicted_sales:.2f}")
|
| 37 |
+
else:
|
| 38 |
+
st.error(f"Error in API request: {response.status_code} - {response.text}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,13 +1,2 @@
|
|
| 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 |
-
|
| 13 |
-
streamlit==1.43.2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
requests==2.32.3
|
| 2 |
+
streamlit==1.45.0
|
|
|