rojasnath commited on
Commit
0e5e7c1
·
verified ·
1 Parent(s): 522fe9e

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +57 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import requests
4
+
5
+ #Streamlit UI for customer churn prediction
6
+ st.title("SuperKart Sales Predictor App")
7
+ st.write("This tool predicts store sales revenue based on store and product details. Enter the required information below.")
8
+
9
+ #Collect user info based on dataset columns
10
+ ProductWeight = st.number_input("Product_Weight", min_value= 0.5, max_value= 100.0),
11
+ ProductSugarContent = st.selectbox("Product_Sugar_Content",["No Sugar", "Low Sugar", "Regular"])
12
+ ProductAllocatedArea = st.number_input("Product_Allocated_Area", min_value=0.001, max_value=0.5),
13
+ ProductType = st.selectbox("Product_Type",["Baking Goods", "Breads", "Breakfast", "Canned", "Dairy", "Frozen Foods", "Fruits and Vegetables", "Hard Drinks", "Health and Hygiene", "Household", "Meat", "Seafood", "Snack Foods", "Soft Drinks", "Starchy Foods"]),
14
+ ProductMRP = st.number_input("Product_MRP", min_value=5, max_value=500),
15
+ StoreID = st.selectbox("Store_Id",["OUT001", "OUT002", "OUT003","OUT004"]),
16
+ StoreSize = st.selectbox("Store_Size", ["Small", "Medium", "High"]),
17
+ StoreLocationCityType = st.selectbox("Store_Location_City_Type",["Tier 1", "Tier 2", "Tier 3"]),
18
+ StoreType = st.selectbox("Store_Type",["Supermarket Type1", "Supermarket Type2", "Grocery Store"]),
19
+ StoreEstablishmentYear = st.number_input("Store_Age", min_value=2023, max_value=2027)
20
+
21
+ #Convert categorical inputs to match model training
22
+ store_data = {
23
+ 'Product_Weight' : ProductWeight,
24
+ 'Product_Sugar_Content' : ProductSugarContent,
25
+ 'Product_Allocated_Area' : ProductAllocatedArea,
26
+ 'Product_Type' : ProductType,
27
+ 'Product_MRP' : ProductMRP,
28
+ 'Store_Id' : StoreID,
29
+ 'Store_Size' : StoreSize,
30
+ 'Store_Location_City_Type' : StoreLocationCityType,
31
+ 'Store_Type' : StoreType,
32
+ 'Store_Age' : StoreEstablishmentYear
33
+ }
34
+
35
+ if st.button("Predict", type='primary'):
36
+ response = requests.post("https://rojasnath/Backend.hf.space/predict", json=store_data)
37
+ if response.status_code == 200:
38
+ result = response.json()
39
+ sales_prediction = result['prediction']
40
+ st.write(f"Based on the information provided, the forecasted sales revenue for the store is ${sales_prediction:.2f}.")
41
+ else:
42
+ st.error("Error in API Request")
43
+
44
+
45
+ #Batch Prediction
46
+ st.subheader("Batch Prediction")
47
+
48
+ file = st.file_uploader("Upload a CSV file", type=["csv"])
49
+ if file is not None:
50
+ if st.button("Predict"):
51
+ response = requests.post("https://rojasnath/Backend.hf.space/predict_batch", files={"file": file})
52
+ if response.status_code == 200:
53
+ result = response.json()
54
+ st.header("Bacth Prediction Results")
55
+ st.write(result)
56
+ else:
57
+ st.error("Error in API Request")
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+
2
+ pandas==2.2.2
3
+ requests==2.32.3
4
+ streamlit==1.43.2