dpanchali commited on
Commit
727990e
·
verified ·
1 Parent(s): f19fb47

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +7 -14
  2. app.py +91 -0
  3. requirements.txt +3 -3
Dockerfile CHANGED
@@ -1,21 +1,14 @@
 
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"]
 
 
 
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import json
4
+ import pandas as pd
5
+
6
+ # Define the backend API URL
7
+ # Replace with the actual URL of your deployed backend API
8
+ BACKEND_API_URL_SINGLE = "YOUR_BACKEND_API_URL/predict_single"
9
+ BACKEND_API_URL_BATCH = "YOUR_BACKEND_API_URL/predict_batch"
10
+
11
+
12
+ st.title("SuperKart Sales Forecasting")
13
+
14
+ st.write("This application forecasts the sales revenue for product-store combinations.")
15
+
16
+ # Option to choose between single prediction and batch prediction
17
+ prediction_mode = st.radio("Select Prediction Mode:", ("Single Prediction", "Batch Prediction"))
18
+
19
+ if prediction_mode == "Single Prediction":
20
+ st.header("Predict Sales for a Single Item")
21
+
22
+ # Input fields for product and store details
23
+ product_id = st.text_input("Product ID")
24
+ product_weight = st.number_input("Product Weight", min_value=0.0)
25
+ product_sugar_content = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar'])
26
+ product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0)
27
+ product_type = st.selectbox("Product Type", ['Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene', 'Snack Foods', 'Meat', 'Hard Drinks', 'Fruits and Vegetables', 'Breads', 'Soft Drinks', 'Breakfast', 'Others', 'Starchy Foods', 'Seafood', 'Household'])
28
+ product_mrp = st.number_input("Product MRP", min_value=0.0)
29
+ store_id = st.selectbox("Store ID", ['OUT004', 'OUT003', 'OUT001', 'OUT002'])
30
+ store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2024)
31
+ store_size = st.selectbox("Store Size", ['Medium', 'High', 'Small'])
32
+ store_location_city_type = st.selectbox("Store Location City Type", ['Tier 2', 'Tier 1', 'Tier 3'])
33
+ store_type = st.selectbox("Store Type", ['Supermarket Type2', 'Departmental Store', 'Supermarket Type1', 'Food Mart'])
34
+
35
+
36
+ if st.button("Predict Sales"):
37
+ # Prepare data for the API request
38
+ input_data = {
39
+ "Product_Id": product_id,
40
+ "Product_Weight": product_weight,
41
+ "Product_Sugar_Content": product_sugar_content,
42
+ "Product_Allocated_Area": product_allocated_area,
43
+ "Product_Type": product_type,
44
+ "Product_MRP": product_mrp,
45
+ "Store_Id": store_id,
46
+ "Store_Establishment_Year": store_establishment_year,
47
+ "Store_Size": store_size,
48
+ "Store_Location_City_Type": store_location_city_type,
49
+ "Store_Type": store_type
50
+ }
51
+
52
+ # Send POST request to the backend API
53
+ response = requests.post(BACKEND_API_URL_SINGLE, json=input_data)
54
+
55
+ # Display the prediction result
56
+ if response.status_code == 200:
57
+ prediction = response.json()['predicted_sales']
58
+ st.success(f"Predicted Sales: {prediction:.2f}")
59
+ else:
60
+ st.error(f"Error: {response.status_code} - {response.text}")
61
+
62
+ elif prediction_mode == "Batch Prediction":
63
+ st.header("Predict Sales for a Batch of Items")
64
+ st.write("Upload a CSV file with product and store details.")
65
+
66
+ uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
67
+
68
+ if uploaded_file is not None:
69
+ try:
70
+ # Read the uploaded CSV file into a DataFrame
71
+ input_df = pd.read_csv(uploaded_file)
72
+ st.write("Uploaded Data:")
73
+ st.dataframe(input_df)
74
+
75
+ if st.button("Predict Sales (Batch)"):
76
+ # Send POST request to the backend API with the CSV file
77
+ files = {'file': uploaded_file.getvalue()}
78
+ response = requests.post(BACKEND_API_URL_BATCH, files=files)
79
+
80
+ # Display the prediction result
81
+ if response.status_code == 200:
82
+ predictions = response.json()['predicted_sales']
83
+ # Display predictions in a DataFrame
84
+ predictions_df = pd.DataFrame({'Predicted_Sales': predictions})
85
+ st.write("Predicted Sales:")
86
+ st.dataframe(predictions_df)
87
+ else:
88
+ st.error(f"Error: {response.status_code} - {response.text}")
89
+
90
+ except Exception as e:
91
+ st.error(f"Error processing file: {e}")
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