Spaces:
Runtime error
Runtime error
Frontend with Streamlit + Docker
Browse files- Dockerfile +1 -1
- requirements.txt +1 -4
- streamlit_app.py +50 -0
Dockerfile
CHANGED
|
@@ -11,6 +11,6 @@ COPY . .
|
|
| 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", "
|
| 15 |
|
| 16 |
# NOTE: Disable XSRF protection for easier external access in order to make batch predictions
|
|
|
|
| 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", "streamlit_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
|
requirements.txt
CHANGED
|
@@ -1,5 +1,2 @@
|
|
| 1 |
streamlit
|
| 2 |
-
|
| 3 |
-
numpy
|
| 4 |
-
xgboost
|
| 5 |
-
scikit-learn
|
|
|
|
| 1 |
streamlit
|
| 2 |
+
requests
|
|
|
|
|
|
|
|
|
streamlit_app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
st.set_page_config(layout="wide", page_title="SuperKart Sales Predictor")
|
| 6 |
+
|
| 7 |
+
st.title("SuperKart: Predict Store Sales")
|
| 8 |
+
|
| 9 |
+
st.markdown("#### Fill in the product and store details:")
|
| 10 |
+
|
| 11 |
+
with st.form("sales_form"):
|
| 12 |
+
Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 13 |
+
City_Tier = st.selectbox("City Tier", ["Tier 1", "Tier 2", "Tier 3"])
|
| 14 |
+
Sugar_Content = st.selectbox("Sugar Content", ["low sugar", "no sugar", "regular"])
|
| 15 |
+
Product_Type = st.selectbox("Product Type (Encoded)", list(range(10))) # simplified
|
| 16 |
+
Store_Id = st.selectbox("Store ID (Encoded)", list(range(5)))
|
| 17 |
+
Store_Type = st.selectbox("Store Type (Encoded)", list(range(4)))
|
| 18 |
+
Product_Weight = st.number_input("Product Weight (Scaled)", -3.0, 3.0, 0.0)
|
| 19 |
+
Product_MRP = st.number_input("Product MRP (Scaled)", -3.0, 3.0, 0.0)
|
| 20 |
+
Allocated_Area = st.number_input("Product Allocated Area (Scaled)", -3.0, 3.0, 0.0)
|
| 21 |
+
Store_Age = st.number_input("Store Age (Scaled)", -3.0, 3.0, 0.0)
|
| 22 |
+
|
| 23 |
+
submitted = st.form_submit_button("Predict")
|
| 24 |
+
|
| 25 |
+
if submitted:
|
| 26 |
+
# Encode manually
|
| 27 |
+
size_map = {"Small": 0, "Medium": 1, "High": 2}
|
| 28 |
+
tier_map = {"Tier 1": 0, "Tier 2": 1, "Tier 3": 2}
|
| 29 |
+
sugar_map = {"low sugar": 0, "no sugar": 1, "regular": 2}
|
| 30 |
+
|
| 31 |
+
input_data = [
|
| 32 |
+
size_map[Store_Size],
|
| 33 |
+
tier_map[City_Tier],
|
| 34 |
+
sugar_map[Sugar_Content],
|
| 35 |
+
Product_Type,
|
| 36 |
+
Store_Id,
|
| 37 |
+
Store_Type,
|
| 38 |
+
Product_Weight,
|
| 39 |
+
Product_MRP,
|
| 40 |
+
Allocated_Area,
|
| 41 |
+
Store_Age
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
backend_url = "https://omm7-superkart-backend.hf.space/predict"
|
| 45 |
+
try:
|
| 46 |
+
response = requests.post(backend_url, json={"data": [input_data]})
|
| 47 |
+
prediction = response.json()["prediction"][0]
|
| 48 |
+
st.success(f"Predicted Sales: ₹ {prediction:,.2f}")
|
| 49 |
+
except Exception as e:
|
| 50 |
+
st.error(f"Something went wrong: {e}")
|