Santhu976 commited on
Commit
161c632
·
verified ·
1 Parent(s): 86c1f76

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +90 -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 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,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Set the title of the Streamlit app
3
+ st.title("SuperKart Product Sales Prediction")
4
+
5
+ # Section for online prediction
6
+ st.subheader("Online Prediction")
7
+
8
+ st.header("Enter Product and Store Details")
9
+
10
+ # Collect user input for product store features
11
+
12
+ product_weight = st.number_input(
13
+ "Product Weight (in kg)", min_value=0.0, step=0.1, value=10.0
14
+ )
15
+
16
+ product_sugar_content = st.selectbox(
17
+ "Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"]
18
+ )
19
+
20
+ product_allocated_area = st.number_input(
21
+ "Product Allocated Area (store fraction)", min_value=0.0, max_value=1.0, step=0.01, value=0.05
22
+ )
23
+
24
+ product_type = st.selectbox(
25
+ "Product Type",
26
+ [
27
+ "Frozen Foods", "Dairy", "Canned", "Baking Goods", "Health and Hygiene",
28
+ "Snack Foods", "Soft Drinks", "Meat", "Fruits and Vegetables", "Breads",
29
+ "Breakfast Foods", "Starchy Foods", "Seafood", "Household", "Others"
30
+ ]
31
+ )
32
+
33
+ product_mrp = st.number_input(
34
+ "Product MRP (Maximum Retail Price)", min_value=0.0, step=1.0, value=150.0
35
+ )
36
+
37
+ store_establishment_year = st.number_input(
38
+ "Store Establishment Year", min_value=1900, max_value=2025, step=1, value=2005
39
+ )
40
+
41
+ store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
42
+
43
+ store_location_city_type = st.selectbox(
44
+ "Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"]
45
+ )
46
+
47
+ store_type = st.selectbox(
48
+ "Store Type",
49
+ ["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"]
50
+ )
51
+
52
+ # Convert user input into a DataFrame
53
+ input_data = pd.DataFrame([{
54
+ 'Product_Weight': product_weight,
55
+ 'Product_Sugar_Content': product_sugar_content,
56
+ 'Product_Allocated_Area': product_allocated_area,
57
+ 'Product_Type': product_type,
58
+ 'Product_Mrp': product_mrp,
59
+ 'Store_Establishment_Year': store_establishment_year,
60
+ 'Store_Size': store_size,
61
+ 'Store_Location_City_Type': store_location_city_type,
62
+ 'Store_Type': store_type
63
+ }])
64
+
65
+ # Make prediction when the "Predict" button is clicked
66
+ if st.button("Predict"):
67
+ #response = requests.post("https://<username>-<repo_id>.hf.space/v1/rental", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
68
+ response = requests.post("https://Santhu976-ProdStoreSalesTotalPredictionBackend.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0])
69
+ if response.status_code == 200:
70
+ prediction = response.json()['Predicted Price']
71
+ st.success(f"Predicted Product_Store_Sales_Total: {prediction}")
72
+ else:
73
+ st.error("Error making prediction.")
74
+
75
+ # Section for batch prediction
76
+ st.subheader("Batch Prediction")
77
+
78
+ # Allow users to upload a CSV file for batch prediction
79
+ uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
80
+
81
+ # Make batch prediction when the "Predict Batch" button is clicked
82
+ if uploaded_file is not None:
83
+ if st.button("Predict Batch"):
84
+ response = requests.post("https://Santhu976-ProdStoreSalesTotalPredictionBackend.hf.space/v1/salesbatch", files={"file": uploaded_file}) # Send file to Flask API
85
+ if response.status_code == 200:
86
+ predictions = response.json()
87
+ st.success("Batch predictions completed!")
88
+ st.write(predictions) # Display the predictions
89
+ else:
90
+ 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