12ongo commited on
Commit
f0156c3
·
verified ·
1 Parent(s): c19f094

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +7 -21
  2. app.py +88 -0
  3. requirements.txt +3 -3
Dockerfile CHANGED
@@ -1,21 +1,7 @@
1
- FROM python:3.9-slim
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- software-properties-common \
9
- git \
10
- && rm -rf /var/lib/apt/lists/*
11
-
12
- COPY requirements.txt ./
13
- COPY src/ ./src/
14
-
15
- RUN pip3 install -r requirements.txt
16
-
17
- EXPOSE 8501
18
-
19
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
20
-
21
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+ COPY . .
5
+ RUN pip install --no-cache-dir -r requirements.txt
6
+
7
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import requests
5
+
6
+ # Configure backend URL (defaults to your Space). You can override in the UI.
7
+ DEFAULT_BACKEND_URL = "https://12ongo-backendproject.hf.space"
8
+ backend_url = st.text_input(
9
+ "Backend URL",
10
+ value=st.secrets.get("BACKEND_URL", DEFAULT_BACKEND_URL),
11
+ help="Override if needed (e.g., local http://127.0.0.1:5000)",
12
+ )
13
+
14
+ st.title("SuperKart Sales Prediction")
15
+
16
+ st.subheader("Online Prediction")
17
+
18
+ # Input widgets
19
+ product_weight = st.number_input("Product Weight", min_value=0.0, value=10.0, step=0.1)
20
+ product_sugar_content = st.selectbox(
21
+ "Product Sugar Content",
22
+ ["low sugar", "regular", "no sugar"],
23
+ )
24
+ product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, value=0.15, step=0.01)
25
+ product_type = st.selectbox(
26
+ "Product Type",
27
+ [
28
+ "meat",
29
+ "snack foods",
30
+ "hard drinks",
31
+ "dairy",
32
+ "canned",
33
+ "soft drinks",
34
+ "health and hygiene",
35
+ "baking goods",
36
+ "bread",
37
+ "breakfast",
38
+ "frozen foods",
39
+ "fruits and vegetables",
40
+ "household",
41
+ "seafood",
42
+ "starchy foods",
43
+ "others",
44
+ ],
45
+ )
46
+ product_mrp = st.number_input("Product MRP", min_value=0.0, value=99.0, step=0.5)
47
+ store_before_2005 = st.checkbox("Store Established Before 2005?", value=True)
48
+ store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
49
+ store_city_type = st.selectbox("Store City Type", ["Tier 1", "Tier 2", "Tier 3"])
50
+ store_type = st.selectbox(
51
+ "Store Type",
52
+ ["Departmental Store", "Supermarket Type 1", "Supermarket Type 2", "Food Mart"],
53
+ )
54
+
55
+ if st.button("Predict Sales"):
56
+ payload = {
57
+ "Product_Weight": product_weight,
58
+ "Product_Sugar_Content": product_sugar_content,
59
+ "Product_Allocated_Area": product_allocated_area,
60
+ "Product_Type": product_type,
61
+ "Product_MRP": product_mrp,
62
+ "Store_Establishment_Year_Before_2005": bool(store_before_2005),
63
+ "Store_Size": store_size,
64
+ "Store_Location_City_Type": store_city_type,
65
+ "Store_Type": store_type,
66
+ }
67
+ try:
68
+ resp = requests.post(f"{backend_url}/v1/sales", json=payload, timeout=30)
69
+ if resp.status_code == 200:
70
+ st.success(f"Predicted Sales: {resp.json().get('Predicted_Sales')}")
71
+ else:
72
+ st.error(f"Error {resp.status_code}: {resp.text}")
73
+ except Exception as e:
74
+ st.error(f"Request failed: {e}")
75
+
76
+ st.subheader("Batch Prediction")
77
+ uploaded_file = st.file_uploader("Upload CSV (same schema as training features)", type=["csv"])
78
+ if uploaded_file is not None:
79
+ if st.button("Predict Batch"):
80
+ try:
81
+ files = {"file": uploaded_file}
82
+ resp = requests.post(f"{backend_url}/v1/salesbatch", files=files, timeout=60)
83
+ if resp.status_code == 200:
84
+ st.write(pd.DataFrame({"Predicted_Sales": resp.json().get("Predicted_Sales", [])}))
85
+ else:
86
+ st.error(f"Error {resp.status_code}: {resp.text}")
87
+ except Exception as e:
88
+ st.error(f"Batch request failed: {e}")
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- altair
2
- pandas
3
- streamlit
 
1
+ pandas==2.2.2
2
+ requests==2.32.3
3
+ streamlit==1.43.2