Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +16 -0
- app.py +61 -0
- requirements.txt +2 -0
Dockerfile
ADDED
|
@@ -0,0 +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 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 |
+
# Install Python dependencies listed in requirements.txt
|
| 11 |
+
RUN pip3 install -r requirements.txt
|
| 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
|
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
|
| 5 |
+
st.title("SuperKart Sales Forecast")
|
| 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", "Regular", "No Sugar"])
|
| 10 |
+
|
| 11 |
+
# Numeric inputs
|
| 12 |
+
Product_Allocated_Area = st.number_input("Product Allocated Area (0–1)", min_value=0.0, max_value=1.0, value=0.05, step=0.01, format="%.2f")
|
| 13 |
+
Product_MRP = st.number_input("Product MRP", min_value=0.0, value=150.00, step=0.5)
|
| 14 |
+
|
| 15 |
+
# Categorical inputs
|
| 16 |
+
Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 17 |
+
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 18 |
+
Store_Type = st.selectbox("Store Type", ["Grocery Store", "Supermarket Type1", "Supermarket Type2", "Supermarket Type3"])
|
| 19 |
+
|
| 20 |
+
# IDs and engineered-style fields to match your template
|
| 21 |
+
Product_Id_char = st.text_input("Product Id", "FD6114")
|
| 22 |
+
Store_Age_Years = st.number_input("Store Age (Years)", min_value=0, value=10, step=1)
|
| 23 |
+
Product_Type_Category = st.selectbox(
|
| 24 |
+
"Product Type Category",
|
| 25 |
+
[
|
| 26 |
+
"Fruits and Vegetables","Snack Foods","Household","Frozen Foods","Dairy",
|
| 27 |
+
"Baking Goods","Health and Hygiene","Hard Drinks","Soft Drinks","Meat",
|
| 28 |
+
"Canned","Breads","Breakfast","Seafood","Others"
|
| 29 |
+
]
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Map UI fields to the backend model's expected feature names
|
| 33 |
+
current_year = datetime.now().year
|
| 34 |
+
payload = {
|
| 35 |
+
"Product_Weight": Product_Weight,
|
| 36 |
+
"Product_Sugar_Content": Product_Sugar_Content,
|
| 37 |
+
"Product_Allocated_Area": Product_Allocated_Area,
|
| 38 |
+
"Product_MRP": Product_MRP,
|
| 39 |
+
"Store_Size": Store_Size,
|
| 40 |
+
"Store_Location_City_Type": Store_Location_City_Type,
|
| 41 |
+
"Store_Type": Store_Type,
|
| 42 |
+
"Product_Id": Product_Id_char, # map Product_Id_char -> Product_Id
|
| 43 |
+
"Store_Establishment_Year": int(current_year - Store_Age_Years), # derive year from age
|
| 44 |
+
"Product_Type": Product_Type_Category # map Product_Type_Category -> Product_Type
|
| 45 |
+
# (Optional) If your model expects Store_Id, add another text_input and include it here
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
# ---- Call your backend Space (replace with your actual username/space) ----
|
| 49 |
+
API_URL = "https://<user_name>-<space_name>.hf.space/v1/sales" # <-- fill in
|
| 50 |
+
|
| 51 |
+
if st.button("Predict", type="primary"):
|
| 52 |
+
try:
|
| 53 |
+
resp = requests.post(API_URL, json=payload, timeout=30)
|
| 54 |
+
if resp.status_code == 200:
|
| 55 |
+
result = resp.json()
|
| 56 |
+
predicted_sales = result.get("Predicted Product_Store_Sales_Total") or next(iter(result.values()))
|
| 57 |
+
st.success(f"Predicted Product Store Sales Total: ₹{float(predicted_sales):,.2f}")
|
| 58 |
+
else:
|
| 59 |
+
st.error(f"API error [{resp.status_code}]: {resp.text}")
|
| 60 |
+
except Exception as e:
|
| 61 |
+
st.error(f"Request failed: {e}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
requests==2.32.3
|
| 2 |
+
streamlit==1.45.0
|