Upload folder using huggingface_hub
Browse files- Dockerfile +10 -9
- app.py +71 -52
- requirements.txt +0 -8
Dockerfile
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
-
# Set
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
-
# Copy
|
| 7 |
COPY . .
|
| 8 |
|
| 9 |
-
# Install dependencies
|
| 10 |
-
RUN pip install --no-cache-dir -
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
#
|
| 16 |
-
CMD ["
|
|
|
|
| 1 |
+
# Use the official Python slim image
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
+
# Set working directory
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
+
# Copy app files
|
| 8 |
COPY . .
|
| 9 |
|
| 10 |
+
# Install dependencies
|
| 11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
|
| 13 |
+
# Expose Streamlit default port
|
| 14 |
+
EXPOSE 7860
|
| 15 |
+
|
| 16 |
+
# Run the Streamlit app
|
| 17 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.enableCORS=false"]
|
app.py
CHANGED
|
@@ -1,53 +1,72 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
|
|
|
| 3 |
import pandas as pd
|
| 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 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import re
|
| 3 |
+
import streamlit as st
|
| 4 |
import pandas as pd
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
valid_store_ids = ["OUT001", "OUT002", "OUT003", "OUT004"]
|
| 8 |
+
store_meta = {
|
| 9 |
+
"OUT001": {"year": 1987, "size": "High", "city_type": "Tier 2", "store_type": "Supermarket Type1"},
|
| 10 |
+
"OUT002": {"year": 1998, "size": "Small", "city_type": "Tier 3", "store_type": "Food Mart"},
|
| 11 |
+
"OUT003": {"year": 1999, "size": "Medium", "city_type": "Tier 1", "store_type": "Departmental Store"},
|
| 12 |
+
"OUT004": {"year": 2009, "size": "Medium", "city_type": "Tier 2", "store_type": "Supermarket Type2"},
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
st.title("SmartKart: Product Sales Prediction")
|
| 16 |
+
st.subheader("Online Prediction")
|
| 17 |
+
|
| 18 |
+
product_id = st.text_input("Product ID (2 uppercase letters + 4 digits, e.g., FD6114)", max_chars=6)
|
| 19 |
+
product_id_valid = bool(re.fullmatch(r"[A-Z]{2}\d{4}", product_id))
|
| 20 |
+
if product_id and not product_id_valid:
|
| 21 |
+
st.error("Invalid Product ID format; it must be 2 uppercase letters followed by 4 digits.")
|
| 22 |
+
elif product_id_valid:
|
| 23 |
+
st.success("Product ID format is valid.")
|
| 24 |
+
|
| 25 |
+
store_id = st.selectbox("Store ID", options=valid_store_ids)
|
| 26 |
+
meta = store_meta[store_id]
|
| 27 |
+
st.text(f"Store Establishment Year: **{meta['year']}**")
|
| 28 |
+
st.text(f"Store Size: **{meta['size']}**")
|
| 29 |
+
st.text(f"Store Location City Type: **{meta['city_type']}**")
|
| 30 |
+
st.text(f"Store Type: **{meta['store_type']}**")
|
| 31 |
+
|
| 32 |
+
product_weight = st.number_input("Product Weight", min_value=0.0, value=12.0, format="%.2f")
|
| 33 |
+
product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
|
| 34 |
+
product_allocated_area = st.slider("Product Allocated Area Ratio", min_value=0.0, max_value=1.0, step=0.001, value=0.05)
|
| 35 |
+
product_type = st.selectbox("Product Type", [
|
| 36 |
+
"Meat", "Snack Foods", "Hard Drinks", "Dairy", "Canned", "Soft Drinks",
|
| 37 |
+
"Health and Hygiene", "Baking Goods", "Bread", "Breakfast", "Frozen Foods",
|
| 38 |
+
"Fruits and Vegetables", "Household", "Seafood", "Starchy Foods", "Others"
|
| 39 |
+
])
|
| 40 |
+
product_mrp = st.number_input("Product MRP", min_value=0.0, value=150.0, format="%.2f")
|
| 41 |
+
|
| 42 |
+
input_data = pd.DataFrame([{
|
| 43 |
+
"Product_Id": product_id,
|
| 44 |
+
"Product_Weight": product_weight,
|
| 45 |
+
"Product_Sugar_Content": product_sugar_content,
|
| 46 |
+
"Product_Allocated_Area": product_allocated_area,
|
| 47 |
+
"Product_Type": product_type,
|
| 48 |
+
"Product_MRP": product_mrp,
|
| 49 |
+
"Store_Id": store_id,
|
| 50 |
+
"Store_Establishment_Year": meta['year'],
|
| 51 |
+
"Store_Size": meta['size'],
|
| 52 |
+
"Store_Location_City_Type": meta['city_type'],
|
| 53 |
+
"Store_Type": meta['store_type'],
|
| 54 |
+
}])
|
| 55 |
+
|
| 56 |
+
if st.button("Predict"):
|
| 57 |
+
if not product_id_valid:
|
| 58 |
+
st.error("Please fix the Product ID before proceeding.")
|
| 59 |
+
else:
|
| 60 |
+
try:
|
| 61 |
+
with st.spinner("Fetching prediction..."):
|
| 62 |
+
response = requests.post(
|
| 63 |
+
"https://ShanRaja/Model_Sales_Prediction_SuperKart.hf.space/v1/sales",
|
| 64 |
+
json=input_data.to_dict(orient="records")[0]
|
| 65 |
+
)
|
| 66 |
+
if response.status_code == 200:
|
| 67 |
+
prediction = response.json().get("Predicted Sales")
|
| 68 |
+
st.success(f"Predicted Product Sales: {prediction}")
|
| 69 |
+
else:
|
| 70 |
+
st.error(f"API Error {response.status_code}: {response.text}")
|
| 71 |
+
except Exception as e:
|
| 72 |
+
st.error(f"Prediction request failed: {e}")
|
requirements.txt
CHANGED
|
@@ -1,11 +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]
|
| 11 |
streamlit==1.43.2
|
|
|
|
| 1 |
pandas==2.2.2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
requests==2.28.1
|
|
|
|
| 3 |
streamlit==1.43.2
|