harishsohani commited on
Commit
42e4e6a
·
verified ·
1 Parent(s): 7aca69b

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +19 -12
  2. app.py +94 -0
  3. requirements.txt +4 -3
Dockerfile CHANGED
@@ -1,20 +1,27 @@
1
- FROM python:3.13.5-slim
 
2
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- git \
9
- && rm -rf /var/lib/apt/lists/*
10
 
11
- COPY requirements.txt ./
12
- COPY src/ ./src/
 
13
 
14
- RUN pip3 install -r requirements.txt
 
15
 
16
- EXPOSE 8501
17
 
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
 
 
 
 
 
 
19
 
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
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 pip install -r requirements.txt
12
+ RUN pip install --no-cache-dir -r requirements.txt
13
 
14
+ # Use environment variable PORT for Hugging Face Spaces
15
+ ENV PORT 8501
16
 
 
17
 
18
+ # Define the command to run the Streamlit app on port 8501 and make it accessible externally
19
+ #CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
20
+ CMD streamlit run app.py \
21
+ --server.port $PORT \
22
+ --server.address 0.0.0.0 \
23
+ --server.headless true \
24
+ --server.enableXsrfProtection false
25
 
26
+
27
+ # NOTE: Disable XSRF protection for easier external access in order to make batch predictions
app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import requests
3
+ import streamlit as st
4
+ import pandas as pd
5
+
6
+ st.title ("SuperKart Product & Store Input Form")
7
+
8
+ st.write ("Predict sales for SuperKart based on product and store details.")
9
+
10
+ # ==============================
11
+ # Section 1: Product Details
12
+ # ==============================
13
+ st.subheader ("Product Details")
14
+
15
+ prod_weight = st.number_input ("Weight", min_value=0.0, max_value=200.0, value=23.0, step=0.1)
16
+ prod_alloc_area = st.number_input ("Allocated Area (fraction 0-1)", min_value=0.0, max_value=1.0, value=0.068)
17
+ prod_mrp = st.number_input ("MRP", min_value=0.0, max_value=1000.0, value=147.0)
18
+ prod_sug_content = st.selectbox ("Sugar Content", ['Low Sugar', 'Regular', 'No Sugar'])
19
+ prod_type = st.selectbox ("Product Type", [
20
+ 'Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene',
21
+ 'Snack Foods', 'Meat', 'Household', 'Hard Drinks', 'Fruits and Vegetables',
22
+ 'Breads', 'Soft Drinks', 'Breakfast', 'Others', 'Starchy Foods', 'Seafood'
23
+ ])
24
+
25
+ # ==============================
26
+ # Section 2: Store Details
27
+ # ==============================
28
+ st.subheader ("Store Details")
29
+
30
+ store_estb_year = st.number_input ("Store Established in Year", min_value=1900, max_value=2025, value=2002)
31
+ store_id = st.selectbox ("Store Id", ['OUT001', 'OUT002', 'OUT003', 'OUT004'])
32
+ store_size = st.selectbox ("Store Size", ['Small', 'Medium', 'High'])
33
+ store_city_type = st.selectbox ("Type of City", ['Tier 1', 'Tier 2', 'Tier 3'])
34
+ store_type = st.selectbox ("Store Type", ['Food Mart', 'Departmental Store', 'Supermarket Type1', 'Supermarket Type2'])
35
+
36
+ # ==========================
37
+ # Single Value Prediction
38
+ # ==========================
39
+ #if st.button("Predict", type='primary'):
40
+ if st.button("Predict Single Product"):
41
+
42
+ # extract the data collected into a structure
43
+ input_data = {
44
+ 'Product_Weight' : prod_weight,
45
+ 'Product_Sugar_Content' : prod_sug_content,
46
+ 'Product_Allocated_Area' : prod_alloc_area,
47
+ 'Product_Type' : prod_type,
48
+ 'Product_MRP' : prod_mrp,
49
+ 'Store_Id' : store_id,
50
+ 'Store_Establishment_Year' : store_estb_year,
51
+ 'Store_Size' : store_size,
52
+ 'Store_Location_City_Type' : store_city_type,
53
+ 'Store_Type' : store_type
54
+ }
55
+
56
+ response = requests.post (
57
+ "https://harishsohani-SuperKartBackEnd.hf.space/v1/SuperKartSales",
58
+ json=input_data
59
+ )
60
+ if response.status_code == 200:
61
+ result = response.json ()
62
+ sales_prediction = result.get ("SalesPrediction") # Extract only the value
63
+ st.success (f"The predicted sales for given input is {sales_prediction}.")
64
+ else:
65
+ st.error (f"Error in API request - {response.status_code}")
66
+
67
+ # ==============================
68
+ # Batch Prediction
69
+ # ==============================
70
+ st.subheader ("Batch Prediction of SuperKart Sales")
71
+
72
+ file = st.file_uploader ("Upload CSV file", type=["csv"])
73
+
74
+ if file is not None and st.button("Predict Batch"):
75
+
76
+ if st.button("Predict for Batch", type='primary'):
77
+
78
+ inputfile = {"file": (file.name, file.getvalue(), "text/csv")}
79
+ response = requests.post(
80
+ "https://harishsohani-SuperKartBackEnd.hf.space/v1/SuperKartBatchSales",
81
+ files=inputfile
82
+ )
83
+
84
+ if response.status_code == 200:
85
+
86
+ result = response.json ()
87
+
88
+ # convert dict to dataframe for better display
89
+ result_df = pd.DataFrame(list(result.items()), columns=["Product_Id", "Predicted_Sales"])
90
+ st.dataframe (result_df)
91
+ #st.header("Batch Prediction Results")
92
+ #st.write(result)
93
+ else:
94
+ st.error (f"Error in API request {response.status_code}")
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
- altair
2
- pandas
3
- streamlit
 
 
1
+ pandas==2.2.2
2
+ numpy==2.0.2
3
+ requests==2.28.1
4
+ streamlit==1.43.2