abhishek1504 commited on
Commit
50c6289
·
verified ·
1 Parent(s): 2436f9d

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +8 -14
  2. app.py +72 -0
  3. requirements.txt +3 -3
Dockerfile CHANGED
@@ -1,20 +1,14 @@
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 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,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import requests
4
+
5
+ # ==================================
6
+ # Streamlit UI
7
+ # ==================================
8
+ st.title("Product Store Sales Prediction App")
9
+ st.write("This app predicts total sales for a product in a store based on product and store features.")
10
+ st.write("Adjust the sliders and input fields below to get a prediction for a single product-store combination.")
11
+
12
+ # -------------------------
13
+ # Single record inputs
14
+ # -------------------------
15
+ Product_Id = st.number_input("Product ID", min_value=1, step=1)
16
+ Product_Weight = st.number_input("Product Weight (kg)", min_value=0.0, step=0.01, value=0.5)
17
+ Product_Sugar_Content = st.number_input("Sugar Content (%)", min_value=0.0, max_value=100.0, step=0.1, value=10.0)
18
+ Product_Allocated_Area = st.number_input("Allocated Area (sq.m)", min_value=0.0, step=0.1, value=50.0)
19
+ Product_Type = st.text_input("Product Type", value="Food")
20
+ Product_MRP = st.number_input("Maximum Retail Price (MRP)", min_value=0.0, step=0.1, value=100.0)
21
+
22
+ Store_Id = st.number_input("Store ID", min_value=1, step=1)
23
+ Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, step=1, value=2000)
24
+ Store_Size = st.number_input("Store Size (sq.m)", min_value=0.0, step=0.1, value=100.0)
25
+ Store_Location_City_Type = st.selectbox("City Type", ["A", "B", "C"])
26
+ Store_Type = st.text_input("Store Type", value="Supermarket")
27
+
28
+ # -------------------------
29
+ # Single prediction
30
+ # -------------------------
31
+ if st.button("Predict Sales", type='primary'):
32
+ input_data = {
33
+ 'Product_Id': Product_Id,
34
+ 'Product_Weight': Product_Weight,
35
+ 'Product_Sugar_Content': Product_Sugar_Content,
36
+ 'Product_Allocated_Area': Product_Allocated_Area,
37
+ 'Product_Type': Product_Type,
38
+ 'Product_MRP': Product_MRP,
39
+ 'Store_Id': Store_Id,
40
+ 'Store_Establishment_Year': Store_Establishment_Year,
41
+ 'Store_Size': Store_Size,
42
+ 'Store_Location_City_Type': Store_Location_City_Type,
43
+ 'Store_Type': Store_Type
44
+ }
45
+
46
+ # Replace with your Hugging Face Space endpoint
47
+ API_URL = "https://abhishek1504-learning-frontend.hf.space/v1/sales"
48
+
49
+ response = requests.post(API_URL, json=input_data)
50
+ if response.status_code == 200:
51
+ result = response.json()
52
+ predicted_sales = result["Predicted_Product_Store_Sales_Total"]
53
+ st.success(f" Predicted Total Product-Store Sales: **{predicted_sales:.2f} units**")
54
+ else:
55
+ st.error("Error in API request")
56
+
57
+ # -------------------------
58
+ # Batch prediction
59
+ # -------------------------
60
+ st.subheader("Batch Prediction")
61
+ file = st.file_uploader("Upload CSV file with multiple product-store records", type=["csv"])
62
+
63
+ if file is not None:
64
+ if st.button("Predict for Batch", type='primary'):
65
+ API_BATCH_URL = "https://abhishek1504-learning-frontend.hf.space/v1/salesbatch"
66
+ response = requests.post(API_BATCH_URL, files={"file": file})
67
+ if response.status_code == 200:
68
+ result = response.json()
69
+ st.header("Batch Prediction Results")
70
+ st.write(result)
71
+ else:
72
+ st.error("Error in API request")
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