omoral02 commited on
Commit
b4fd459
·
verified ·
1 Parent(s): 5ffa154

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +70 -0
  3. requirements.txt +6 -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,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ import numpy as np
5
+
6
+ # UI Title and Subtitle
7
+ st.title("🛒 SuperKart Sales Forecasting App")
8
+ st.write("This tool predicts **product-level revenue** in a specific store using historical and categorical inputs.")
9
+
10
+ # UI for Input Features
11
+ st.subheader("Enter Product & Store Details:")
12
+
13
+ # Categorical Inputs
14
+ product_type = st.selectbox("Product Type", [
15
+ "Meat", "Snack Foods", "Soft Drinks", "Dairy", "Household", "Fruits and Vegetables",
16
+ "Frozen Foods", "Breakfast", "Baking Goods", "Health and Hygiene", "Starchy Foods"
17
+ ])
18
+
19
+ store_type = st.selectbox("Store Type", [
20
+ "Supermarket Type1", "Supermarket Type2", "Supermarket Type3", "Grocery Store"
21
+ ])
22
+
23
+ city_type = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])
24
+ store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
25
+ sugar_content = st.selectbox("Product Sugar Content", ["No Sugar", "Low Sugar", "Regular"])
26
+
27
+ # Numerical Inputs
28
+ product_weight = st.number_input("Product Weight (kg)", min_value=0.0, max_value=50.0, value=10.0, step=0.1)
29
+ product_mrp = st.number_input("Product MRP", min_value=0.0, max_value=1000.0, value=200.0, step=1.0)
30
+ allocated_area = st.number_input("Allocated Display Area (0-1)", min_value=0.0, max_value=1.0, value=0.2, step=0.01)
31
+ store_est_year = st.number_input("Store Establishment Year", min_value=1950, max_value=2025, value=2010)
32
+
33
+ # Convert to DataFrame
34
+ input_data = pd.DataFrame({
35
+ 'Product_Type': [product_type],
36
+ 'Store_Type': [store_type],
37
+ 'Store_Location_City_Type': [city_type],
38
+ 'Store_Size': [store_size],
39
+ 'Product_Sugar_Content': [sugar_content],
40
+ 'Product_Weight': [product_weight],
41
+ 'Product_MRP': [product_mrp],
42
+ 'Product_Allocated_Area': [allocated_area],
43
+ 'Store_Establishment_Year': [store_est_year],
44
+ })
45
+
46
+ # Make prediction when the "Predict" button is clicked
47
+ if st.button("Predict"):
48
+ response = requests.post("https://huggingface.co/spaces/omoral02/RevenuePredictionBackend/v1/predict", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
49
+ if response.status_code == 200:
50
+ prediction = response.json()['Predicted Price (in dollars)']
51
+ st.success(f"Predicted Revenue (in dollars): {prediction}")
52
+ else:
53
+ st.error("Error making prediction.")
54
+
55
+ # Section for batch prediction
56
+ st.subheader("Batch Prediction")
57
+
58
+ # Allow users to upload a CSV file for batch prediction
59
+ uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
60
+
61
+ # Make batch prediction when the "Predict Batch" button is clicked
62
+ if uploaded_file is not None:
63
+ if st.button("Predict Batch"):
64
+ response = requests.post("https://huggingface.co/spaces/omoral02/RevenuePredictionBackend/v1/batch", files={"file": uploaded_file}) # Send file to Flask API
65
+ if response.status_code == 200:
66
+ predictions = response.json()
67
+ st.success("Batch predictions completed!")
68
+ st.write(predictions) # Display the predictions
69
+ else:
70
+ st.error("Error making batch prediction.")
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ pandas==2.2.2
2
+ numpy==2.0.2
3
+ scikit-learn==1.6.1
4
+ xgboost==2.1.4
5
+ joblib==1.4.2
6
+ streamlit==1.43.2