mdsalmon159 commited on
Commit
1a29583
·
verified ·
1 Parent(s): a34a700

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +57 -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,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import requests
4
+
5
+ # Set the title of the Streamlit app
6
+ st.title("SuperKart sales Prediction")
7
+
8
+ # Section for online prediction
9
+ st.subheader("Online Prediction")
10
+
11
+ # Collect user input for property features
12
+ Product_Sugar_Content = st.selectbox("Product_Sugar_Content", ["Low Sugar", "Regular", "No Sugar","reg"] )
13
+ Product_Type = st.selectbox("Product_Type",["Fruits and Vegetables","Snack Foods","Frozen Foods",
14
+ "Dairy","Household","Baking Goods","Canned",
15
+ "Health and Hygiene","Meat","Soft Drinks","Breads",
16
+ "Hard Drinks","Others","Starchy Foods","Breakfast","Seafood"])
17
+ Store_Id = st.selectbox("Store_Id", [ "OUT001", "OUT002","OUT003"] )
18
+ Store_Size= st.selectbox("Store_Size", ["Medium", "High","Small"] )
19
+ Store_Location_City_Type = st.selectbox("Store_Location_City_Type", ["Tier 1", "Tier 2","Tier 3"] )
20
+ Store_Type = st.selectbox("Store_Type", ["Supermarket Type1", "Supermarket Type2","Departmental Store","Food Mart"] )
21
+ Product_Weight = st.number_input("Product_Weight", min_value=1, step=1, value=1)
22
+ Product_MRP = st.number_input("Product_MRP", min_value=1, step=1, value=1)
23
+
24
+
25
+ # Convert user input into a DataFrame
26
+ input_data = pd.DataFrame([{
27
+ 'Product_Sugar_Content': Product_Sugar_Content,
28
+ 'Product_Type': Product_Type,
29
+ 'Store_Id': Store_Id,
30
+ 'Store_Size': Store_Size,
31
+ 'Store_Type': Store_Type,
32
+ 'Product_Weight': Product_Weight,
33
+ 'Product_MRP': Product_MRP
34
+ }])
35
+
36
+ # Make prediction when the "Predict" button is clicked
37
+ if st.button("Predict"):
38
+ response = requests.post("https://huggingface.co/spaces/mdsalmon159/SalesPredictionBackend.hf.space/v1/sales", json=input_data.to_dict(orient='records' ) [0])
39
+ if response.status_code == 200:
40
+ prediction = response. json() ['Predicted Price (in dollars)']
41
+ st.success(f"Predicted Rental Price (in dollars): {prediction}")
42
+ else:
43
+ st.error("Error making prediction.")
44
+
45
+ # Section for batch prediction
46
+ st.subheader("Batch Prediction")
47
+
48
+ # Make batch prediction when the "Predict Batch" button is clicked
49
+ if uploaded_file is not None:
50
+ if st.button("Predict Batch"):
51
+ response = requests.post("https://huggingface.co/spaces/mdsalmon159/SalesPredictionBackend.hf.space/v1/sales_batch", files={"file": uploaded_file}) # S
52
+ if response.status_code == 200:
53
+ predictions = response. json( )
54
+ st.success("Batch predictions completed!")
55
+ st.write(predictions) # Display the predictions
56
+ else:
57
+ 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