cnaditoka commited on
Commit
e9d321c
·
verified ·
1 Parent(s): 17192ac

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +61 -0
  3. requirements.txt +3 -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 7860 and make it accessible externally
14
+ CMD ["streamlit", "run", "app.py", "--server.port=7860", "--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,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import streamlit as st
3
+ import pandas as pd
4
+
5
+ st.title("SuperKart Sales Revenue Prediction")
6
+
7
+ # Single Prediction
8
+ st.subheader("Single Prediction")
9
+
10
+ # Input fields for product data
11
+ Product_Weight = st.number_input("weight of each product", min_value=0.0, value=0.0)
12
+ Product_Sugar_Content = st.selectbox("sugar content of each product", ["Low Sugar", "Regular", "No Sugar"])
13
+ Product_Allocated_Area = st.number_input("allocated display area of each product", min_value=0.0, value=0.0)
14
+ Product_Type = st.text_input("broad category for each product")
15
+ Product_MRP = st.number_input("maximum retail price of each product", min_value=0.0, value=0.0)
16
+ Store_Id = st.text_input("unique identifier of each store")
17
+ Store_Establishment_Year = st.number_input("year in which the store was established", min_value=1900, max_value=2030, value=1990)
18
+ Store_Size = st.selectbox("size of the store depending on sq. feet", ["High", "Medium", "Small"])
19
+ Store_Location_City_Type = st.selectbox("type of city in which the store is located", ["Tier 1", "Tier 2", "Tier 3"])
20
+ Store_Type = st.selectbox("type of store depending on the products that are being sold there", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"])
21
+
22
+ # Convert user input into a DataFrame
23
+ input_data = {
24
+ 'Product_Weight': Product_Weight,
25
+ 'Product_Sugar_Content': Product_Sugar_Content,
26
+ 'Product_Allocated_Area': Product_Allocated_Area,
27
+ 'Product_Type': Product_Type,
28
+ 'Product_MRP': Product_MRP,
29
+ 'Store_Id': Store_Id,
30
+ 'Store_Establishment_Year': Store_Establishment_Year,
31
+ 'Store_Size': Store_Size,
32
+ 'Store_Location_City_Type': Store_Location_City_Type,
33
+ 'Store_Type': Store_Type
34
+ }
35
+
36
+ # Make prediction when the "Predict" button is clicked
37
+ if st.button("Predict", type='primary'):
38
+ response = requests.post("https://cnaditoka-SuperKartModelBackend.hf.space/v1/sales_revenue", json=input_data)
39
+ if response.status_code == 200:
40
+ result = response.json()
41
+ predicted_sales_revenue = result["predicted_sales_revenue"] # Extract only the value
42
+ st.success(f"Predicted Sales Revenue (in dollars): {predicted_sales_revenue}")
43
+ else:
44
+ st.error("Error making prediction.")
45
+
46
+ # Batch Prediction
47
+ st.subheader("Batch Prediction")
48
+
49
+ # Allow users to upload a CSV file for batch prediction
50
+ file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
51
+
52
+ # Make batch prediction when the "Predict for Batch" button is clicked
53
+ if file is not None:
54
+ if st.button("Predict for Batch", type='primary'):
55
+ response = requests.post("https://cnaditoka-SuperKartModelBackend.hf.space/v1/sales_revenue_batch", files={"file": file})
56
+ if response.status_code == 200:
57
+ result = response.json()
58
+ st.success("Batch predictions completed!")
59
+ st.write(result)
60
+ else:
61
+ st.error("Error making batch prediction.")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas==2.2.2
2
+ requests==2.28.1
3
+ streamlit==1.43.2