Yash0204 commited on
Commit
f8b6687
Β·
verified Β·
1 Parent(s): 80b8a42

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +8 -13
  2. app.py +101 -0
  3. requirements.txt +3 -3
Dockerfile CHANGED
@@ -1,21 +1,16 @@
 
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
+ # 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 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", "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
app.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import requests
4
+ import pandas as pd
5
+
6
+ # Title and description
7
+ st.set_page_config(page_title="SuperKart Store Sales Forecast", layout="centered")
8
+ st.title('πŸ“ˆ SuperKart Store Sales Forecast')
9
+ st.write('Enter product and store details to predict the sales total or upload a CSV for batch forecasting.')
10
+
11
+ # --- Online Prediction ---
12
+ st.header('πŸ›’ Product and Store Details (Single Forecast)')
13
+
14
+ col1, col2 = st.columns(2)
15
+
16
+ with col1:
17
+ product_weight = st.number_input('Product Weight (kg)', min_value=0.0, format="%.2f")
18
+ product_mrp = st.number_input('Product MRP (β‚Ή)', min_value=0.0, format="%.2f")
19
+ product_sugar_content = st.selectbox('Product Sugar Content', ['Low Sugar', 'Regular', 'No Sugar'])
20
+ product_allocated_area = st.number_input('Product Allocated Area (0.0 - 1.0)', min_value=0.0, max_value=1.0, format="%.4f")
21
+ product_type = st.selectbox('Product Type', [
22
+ 'Meat', 'Snack Foods', 'Hard Drinks', 'Dairy', 'Canned', 'Soft Drinks',
23
+ 'Health and Hygiene', 'Baking Goods', 'Bread', 'Breakfast', 'Frozen Foods',
24
+ 'Fruits and Vegetables', 'Household', 'Seafood', 'Starchy Foods', 'Others'
25
+ ])
26
+
27
+ with col2:
28
+ store_id = st.selectbox('Store ID', ['OUT001', 'OUT002', 'OUT003', 'OUT004'])
29
+ store_establishment_year = st.number_input('Store Establishment Year', min_value=1980, max_value=2025, step=1)
30
+ store_size = st.selectbox('Store Size', ['High', 'Medium', 'Small'])
31
+ store_location_city_type = st.selectbox('Store Location City Type', ['Tier 1', 'Tier 2', 'Tier 3'])
32
+ store_type = st.selectbox('Store Type', ['Departmental Store', 'Supermarket Type1', 'Supermarket Type2', 'Food Mart'])
33
+
34
+ # Predict Button
35
+ if st.button('πŸ“Š Predict Sales Forecast'):
36
+ input_data = {
37
+ 'Product_Weight': product_weight,
38
+ 'Product_MRP': product_mrp,
39
+ 'Product_Sugar_Content': product_sugar_content,
40
+ 'Product_Allocated_Area': product_allocated_area,
41
+ 'Product_Type': product_type,
42
+ 'Store_Id': store_id,
43
+ 'Store_Establishment_Year': store_establishment_year,
44
+ 'Store_Size': store_size,
45
+ 'Store_Location_City_Type': store_location_city_type,
46
+ 'Store_Type': store_type
47
+ }
48
+
49
+ api_url = 'https://Yash0204-API-SuperKart-Backend.hf.space/v1/sales'
50
+
51
+ try:
52
+ response = requests.post(api_url, json=input_data)
53
+
54
+ if response.status_code == 200:
55
+ prediction_result = response.json()
56
+ predicted_sales = prediction_result.get('predicted_product_store_sales_total')
57
+
58
+ if predicted_sales is not None:
59
+ st.success(f'βœ… Predicted Product Store Sales Total: β‚Ή{predicted_sales:.2f}')
60
+ else:
61
+ st.error('❌ Prediction not found in the response.')
62
+
63
+ elif response.status_code == 400:
64
+ st.error(f'❌ API Error: Invalid input data. Details: {response.json().get("error", "Unknown error")}')
65
+ else:
66
+ st.error(f'❌ API Error: Status Code {response.status_code}. Details: {response.text}')
67
+
68
+ except requests.exceptions.RequestException as e:
69
+ st.error(f'❌ Connection Error: {e}')
70
+ except Exception as e:
71
+ st.error(f'❌ Unexpected Error: {e}')
72
+
73
+ st.markdown("---")
74
+
75
+ # --- Batch Forecast ---
76
+ st.header("πŸ“ Batch Forecast using CSV Upload")
77
+ uploaded_file = st.file_uploader("Upload a CSV file containing product/store data", type=["csv"])
78
+
79
+ if uploaded_file is not None:
80
+ if st.button("πŸ“₯ Predict Batch Sales Forecast"):
81
+ api_batch_url = "https://Yash0204-API-SuperKart-Backend.hf.space/v1/salesbatch"
82
+
83
+ try:
84
+ response = requests.post(api_batch_url, files={"file": uploaded_file})
85
+
86
+ if response.status_code == 200:
87
+ result = response.json()
88
+ df_result = pd.DataFrame(result)
89
+ st.success("βœ… Batch predictions completed.")
90
+ st.dataframe(df_result)
91
+ else:
92
+ st.error(f'❌ Batch Prediction Error: {response.status_code} - {response.text}')
93
+
94
+ except requests.exceptions.RequestException as e:
95
+ st.error(f'❌ Connection Error: {e}')
96
+ except Exception as e:
97
+ st.error(f'❌ Unexpected Error: {e}')
98
+
99
+ st.info("ℹ️ Please ensure your backend API supports `/v1/sales` and `/v1/salesbatch` endpoints.")
100
+
101
+
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- altair
2
- pandas
3
- streamlit
 
1
+ pandas==2.2.2
2
+ requests==2.28.1
3
+ streamlit==1.43.2