Spaces:
Sleeping
Sleeping
Update SuperKart frontend
Browse files- Dockerfile +6 -32
- requirements.txt +1 -13
- streamlit_app.py +66 -0
Dockerfile
CHANGED
|
@@ -1,38 +1,12 @@
|
|
| 1 |
-
|
| 2 |
-
FROM python:3.9-slim
|
| 3 |
|
| 4 |
-
# Set the working directory inside the container to /app
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
-
|
| 8 |
-
RUN
|
| 9 |
|
| 10 |
-
|
| 11 |
-
RUN mkdir -p /home/app_user/.streamlit && \
|
| 12 |
-
chown -R app_user:app_user /home/app_user/.streamlit
|
| 13 |
|
| 14 |
-
|
| 15 |
-
COPY . .
|
| 16 |
|
| 17 |
-
|
| 18 |
-
RUN pip3 install -r requirements.txt
|
| 19 |
-
|
| 20 |
-
# Change ownership of app directory to app_user
|
| 21 |
-
RUN chown -R app_user:app_user /app
|
| 22 |
-
|
| 23 |
-
# Switch to non-root user
|
| 24 |
-
USER app_user
|
| 25 |
-
|
| 26 |
-
# Set HOME environment variable
|
| 27 |
-
ENV HOME=/home/app_user
|
| 28 |
-
|
| 29 |
-
# Create Streamlit config to disable usage stats and set proper permissions
|
| 30 |
-
RUN mkdir -p $HOME/.streamlit && \
|
| 31 |
-
echo "[browser]" > $HOME/.streamlit/config.toml && \
|
| 32 |
-
echo "gatherUsageStats = false" >> $HOME/.streamlit/config.toml && \
|
| 33 |
-
echo "[server]" >> $HOME/.streamlit/config.toml && \
|
| 34 |
-
echo "enableXsrfProtection = false" >> $HOME/.streamlit/config.toml && \
|
| 35 |
-
echo "enableCORS = false" >> $HOME/.streamlit/config.toml
|
| 36 |
-
|
| 37 |
-
# Define the command to run the Streamlit app on port 8501 and make it accessible externally
|
| 38 |
-
CMD ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
|
|
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install -r requirements.txt
|
| 7 |
|
| 8 |
+
COPY streamlit_app.py .
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
EXPOSE 7860
|
|
|
|
| 11 |
|
| 12 |
+
CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,17 +1,5 @@
|
|
| 1 |
-
# SuperKart
|
| 2 |
-
# Streamlit web framework
|
| 3 |
streamlit==1.28.1
|
| 4 |
-
|
| 5 |
-
# Data processing and visualization
|
| 6 |
pandas==2.2.3
|
| 7 |
numpy>=1.19.3,<2.0
|
| 8 |
-
|
| 9 |
-
# HTTP requests for API calls
|
| 10 |
requests==2.31.0
|
| 11 |
-
|
| 12 |
-
# Interactive plotting for charts
|
| 13 |
-
plotly==5.17.0
|
| 14 |
-
|
| 15 |
-
# JSON handling (built-in, but explicit for clarity)
|
| 16 |
-
# datetime (built-in Python module)
|
| 17 |
-
# os (built-in Python module)
|
|
|
|
| 1 |
+
# SuperKart Frontend Dependencies
|
|
|
|
| 2 |
streamlit==1.28.1
|
|
|
|
|
|
|
| 3 |
pandas==2.2.3
|
| 4 |
numpy>=1.19.3,<2.0
|
|
|
|
|
|
|
| 5 |
requests==2.31.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
streamlit_app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
# Page config
|
| 6 |
+
st.set_page_config(page_title="SuperKart Sales Forecasting", layout="wide")
|
| 7 |
+
|
| 8 |
+
# API URL - your working backend
|
| 9 |
+
API_BASE_URL = "https://hackstert-greatlearningproject.hf.space"
|
| 10 |
+
|
| 11 |
+
st.title("SuperKart Sales Forecasting")
|
| 12 |
+
st.write("Enter product details to get sales prediction")
|
| 13 |
+
|
| 14 |
+
# Simple form
|
| 15 |
+
with st.form("prediction_form"):
|
| 16 |
+
col1, col2 = st.columns(2)
|
| 17 |
+
|
| 18 |
+
with col1:
|
| 19 |
+
st.subheader("Product Info")
|
| 20 |
+
product_weight = st.number_input("Weight (kg)", value=12.5)
|
| 21 |
+
product_mrp = st.number_input("Price ($)", value=150.0)
|
| 22 |
+
product_sugar_content = st.selectbox("Sugar Content", ["Low Sugar", "Regular"])
|
| 23 |
+
product_type = st.selectbox("Product Type", ["Dairy", "Soft Drinks", "Meat", "Fruits and Vegetables"])
|
| 24 |
+
|
| 25 |
+
with col2:
|
| 26 |
+
st.subheader("Store Info")
|
| 27 |
+
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 28 |
+
store_type = st.selectbox("Store Type", ["Supermarket Type1", "Grocery Store"])
|
| 29 |
+
store_location = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 30 |
+
store_year = st.number_input("Establishment Year", value=2009)
|
| 31 |
+
|
| 32 |
+
if st.form_submit_button("Predict Sales"):
|
| 33 |
+
# Prepare data
|
| 34 |
+
data = {
|
| 35 |
+
"Product_Weight": product_weight,
|
| 36 |
+
"Product_MRP": product_mrp,
|
| 37 |
+
"Product_Sugar_Content": product_sugar_content,
|
| 38 |
+
"Product_Type": product_type,
|
| 39 |
+
"Store_Size": store_size,
|
| 40 |
+
"Store_Type": store_type,
|
| 41 |
+
"Store_Location_City_Type": store_location,
|
| 42 |
+
"Store_Establishment_Year": store_year
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
try:
|
| 46 |
+
# Call API
|
| 47 |
+
response = requests.post(f"{API_BASE_URL}/predict", json=data)
|
| 48 |
+
|
| 49 |
+
if response.status_code == 200:
|
| 50 |
+
result = response.json()
|
| 51 |
+
st.success(f"Predicted Sales: {result['prediction_formatted']}")
|
| 52 |
+
else:
|
| 53 |
+
st.error(f"API Error: {response.status_code}")
|
| 54 |
+
except Exception as e:
|
| 55 |
+
st.error(f"Connection Error: {str(e)}")
|
| 56 |
+
|
| 57 |
+
# Health check
|
| 58 |
+
if st.button("Check API Status"):
|
| 59 |
+
try:
|
| 60 |
+
response = requests.get(f"{API_BASE_URL}/")
|
| 61 |
+
if response.status_code == 200:
|
| 62 |
+
st.success("API is healthy!")
|
| 63 |
+
else:
|
| 64 |
+
st.error("API not responding")
|
| 65 |
+
except:
|
| 66 |
+
st.error("Cannot connect to API")
|