Anil28053 commited on
Commit
88dc0d8
·
verified ·
1 Parent(s): 92e746c

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 requests
2
+ import streamlit as st
3
+ import pandas as pd
4
+
5
+ st.title("Sales Forecaster")
6
+
7
+ # Batch Prediction
8
+ st.subheader("Predicting Sales")
9
+
10
+ # Input fields for product data
11
+ Product_Id = st.text_input("Product ID", value="FD6114")
12
+ Product_Weight = st.number_input("Product Weight", min_value=0.0, max_value=22.0, format="%.2f")
13
+ Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
14
+ Product_Allocated_Area = st.number_input("Product Allocated Area (Ratio of Total Area) ", min_value=0.0, max_value=1.0, format="%.2f")
15
+ Product_Type = st.selectbox("Type Of Product", ["Fruits and Vegetables", "Snack Foods", "Frozen Foods", "Dairy", "Household", "Baking Goods", "Canned", "Health and Hygiene", "Meat", "Soft Drinks", "Breads", "Hard Drinks","Others", "Starchy Foods", "Breakfast", "Seafood"])
16
+ Product_MRP = st.number_input("Price of Product", min_value=0.0, format="%.2f")
17
+ Store_Id = st.selectbox("Store ID", ["OUT004", "OUT001", "OUT003", "OUT002"])
18
+ Store_Establishment_Year = st.number_input("Year of Store Establishment", min_value=1800, max_value=2025, value=2008)
19
+ Store_Size = st.selectbox("Size of Store", ["High", "Medium", "Small"])
20
+ Store_Location_City_Type = st.selectbox("City Tier of the Store", ["Tier 1", "Tier 2", "Tier 3"])
21
+ Store_Type = st.selectbox("Type of Store", ["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"])
22
+
23
+ product_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
+ if st.button("Predict", type='primary'):
37
+ response = requests.post("https://Anil28053-Backend.hf.space/v1/customer", json=product_data) # enter user name and space name before running the cell
38
+ if response.status_code == 200:
39
+ result = response.json()
40
+ sales_prediction = result["Prediction"] # Extract only the value
41
+ st.write(f"Based on the information provided, the product with ID {Product_Id} is likely to sell {sales_prediction}.")
42
+ else:
43
+ st.error("Error in API request")
44
+
45
+ # Batch Prediction
46
+ st.subheader("Batch Prediction")
47
+
48
+ file = st.file_uploader("Upload CSV file", type=["csv"])
49
+ if file is not None:
50
+ if st.button("Predict for Batch", type='primary'):
51
+ response = requests.post("https://Anil28053-Backend.hf.space/v1/customerbatch", files={"file": file}) # enter user name and space name before running the cell
52
+ if response.status_code == 200:
53
+ result = response.json()
54
+ st.header("Batch Prediction Results")
55
+ st.write(result)
56
+ else:
57
+ st.error("Error in API request")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas==2.2.2
2
+ requests==2.28.1
3
+ streamlit==1.43.2