Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- Dockerfile (2) +23 -0
- app (2).py +58 -0
- random_forest_pipeline.pkl +3 -0
- requirements (2).txt +5 -0
Dockerfile (2)
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Base image: lightweight Python 3.9
|
| 2 |
+
FROM python:3.9-slim-buster
|
| 3 |
+
|
| 4 |
+
# Set container working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy project files into the container
|
| 8 |
+
COPY . /app
|
| 9 |
+
|
| 10 |
+
# Environment variable for Streamlit configuration
|
| 11 |
+
ENV STREAMLIT_CONFIG_DIR=/app/.streamlit
|
| 12 |
+
|
| 13 |
+
# Create the Streamlit configuration directory
|
| 14 |
+
RUN mkdir -p ${STREAMLIT_CONFIG_DIR}
|
| 15 |
+
|
| 16 |
+
# Install dependencies (no cache)
|
| 17 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 18 |
+
|
| 19 |
+
# Default command to run the Streamlit app
|
| 20 |
+
CMD ["streamlit", "run", "app.py", \
|
| 21 |
+
"--server.port=8501", \
|
| 22 |
+
"--server.address=0.0.0.0", \
|
| 23 |
+
"--server.enableXsrfProtection=false"]
|
app (2).py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# Configure page
|
| 6 |
+
st.set_page_config(page_title="SuperKart Sales Estimator", layout="centered")
|
| 7 |
+
st.title("SuperKart Sales Forecast Tool")
|
| 8 |
+
|
| 9 |
+
# Input form
|
| 10 |
+
st.subheader("Provide Product & Store Information")
|
| 11 |
+
|
| 12 |
+
col_left, col_right = st.columns(2)
|
| 13 |
+
|
| 14 |
+
with col_left:
|
| 15 |
+
weight = st.number_input("Product Weight (in kg)", min_value=0.0, step=0.1, value=1.0)
|
| 16 |
+
sugar_level = st.selectbox("Sugar Content", ["Low", "Medium", "Regular", "reg"])
|
| 17 |
+
allocated_area = st.number_input("Display Area (sq.m)", min_value=0.01, step=0.01, value=1.5)
|
| 18 |
+
category = st.selectbox("Category", [
|
| 19 |
+
"Baking Goods", "Canned", "Dairy", "Frozen Foods", "Health and Hygiene",
|
| 20 |
+
"Household", "Meat", "Others", "Snack Foods", "Soft Drinks", "Starchy Foods"
|
| 21 |
+
])
|
| 22 |
+
mrp = st.number_input("MRP ($)", min_value=1.0, max_value=1000.0, step=1.0, value=100.0)
|
| 23 |
+
|
| 24 |
+
with col_right:
|
| 25 |
+
establishment_year = st.number_input("Year Store Opened", min_value=1990, max_value=2025, step=1, value=2010)
|
| 26 |
+
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 27 |
+
city_tier = st.selectbox("Location Tier", ["Tier 1", "Tier 2", "Tier 3"])
|
| 28 |
+
store_format = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Supermarket Type3", "Grocery Store"])
|
| 29 |
+
|
| 30 |
+
# Create JSON payload
|
| 31 |
+
payload = {
|
| 32 |
+
"Product_Weight": weight,
|
| 33 |
+
"Product_Sugar_Content": sugar_level,
|
| 34 |
+
"Product_Allocated_Area": allocated_area,
|
| 35 |
+
"Product_Type": category,
|
| 36 |
+
"Product_MRP": mrp,
|
| 37 |
+
"Store_Establishment_Year": establishment_year,
|
| 38 |
+
"Store_Size": store_size,
|
| 39 |
+
"Store_Location_City_Type": city_tier,
|
| 40 |
+
"Store_Type": store_format
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
# Button to call API
|
| 44 |
+
if st.button("Get Sales Prediction"):
|
| 45 |
+
with st.spinner("Processing your request..."):
|
| 46 |
+
try:
|
| 47 |
+
api_url = "https://mohith96-SuperKartBackend.hf.space/predict"
|
| 48 |
+
response = requests.post(api_url, json=payload, timeout=10)
|
| 49 |
+
if response.status_code == 200:
|
| 50 |
+
result = response.json()
|
| 51 |
+
if "Predicted_Sales" in result:
|
| 52 |
+
st.success(f"Predicted Sales: $ {result['Predicted_Sales']:.2f}")
|
| 53 |
+
else:
|
| 54 |
+
st.warning(f"Unexpected response: {result}")
|
| 55 |
+
else:
|
| 56 |
+
st.error(f"API returned {response.status_code}: {response.text}")
|
| 57 |
+
except Exception as error:
|
| 58 |
+
st.error(f"Failed to reach API: {error}")
|
random_forest_pipeline.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:84816b0dbb03c08b0083fe89dae95480cbd696be411c267fff7abf41370f1768
|
| 3 |
+
size 34999706
|
requirements (2).txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|
| 3 |
+
numpy
|
| 4 |
+
requests
|
| 5 |
+
plotly
|