yokesh1999 commited on
Commit
4610f9e
·
verified ·
1 Parent(s): a69c1ed

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +14 -0
  2. app.py +100 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"]
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import requests
4
+
5
+ # Streamlit UI for SuperKart Sales Revenue Forecasting
6
+ st.title("SuperKart Sales Revenue Forecasting App")
7
+ st.write("This app predicts the total sales revenue for product-store combinations based on product and store features.")
8
+ st.write("Adjust the values below to get a sales prediction.")
9
+
10
+ # Collect user input using sliders and selectboxes
11
+ col1, col2 = st.columns(2)
12
+
13
+ with col1:
14
+ st.subheader("Product Features")
15
+ Product_Weight = st.slider("Product Weight", 5.0, 25.0, 12.5, 0.1)
16
+ Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
17
+ Product_Allocated_Area = st.slider("Product Allocated Area (ratio)", 0.0, 0.5, 0.05, 0.01)
18
+ Product_Type = st.selectbox("Product Type", [
19
+ "Meat", "Snack Foods", "Hard Drinks", "Dairy", "Canned", "Soft Drinks",
20
+ "Health and Hygiene", "Baking Goods", "Bread", "Breakfast", "Frozen Foods",
21
+ "Fruits and Vegetables", "Household", "Seafood", "Starchy Foods", "Others"
22
+ ])
23
+ Product_MRP = st.slider("Product MRP (Maximum Retail Price)", 50.0, 300.0, 150.0, 1.0)
24
+
25
+ with col2:
26
+ st.subheader("Store Features")
27
+ Store_Establishment_Year = st.slider("Store Establishment Year", 1985, 2015, 2000, 1)
28
+ Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
29
+ Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
30
+ Store_Type = st.selectbox("Store Type", [
31
+ "Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"
32
+ ])
33
+
34
+ # Create input data dictionary
35
+ input_data = {
36
+ 'Product_Weight': Product_Weight,
37
+ 'Product_Sugar_Content': Product_Sugar_Content,
38
+ 'Product_Allocated_Area': Product_Allocated_Area,
39
+ 'Product_Type': Product_Type,
40
+ 'Product_MRP': Product_MRP,
41
+ 'Store_Establishment_Year': Store_Establishment_Year,
42
+ 'Store_Size': Store_Size,
43
+ 'Store_Location_City_Type': Store_Location_City_Type,
44
+ 'Store_Type': Store_Type
45
+ }
46
+
47
+ if st.button("Predict Sales Revenue", type='primary'):
48
+ # Replace with your Hugging Face backend space URL
49
+ api_url = "https://<----user-name---->-<---repo name--->.hf.space/v1/sales" # Enter user name and space name
50
+ try:
51
+ response = requests.post(api_url, json=input_data, timeout=30)
52
+ if response.status_code == 200:
53
+ result = response.json()
54
+ predicted_sales = result["Predicted_Sales_Total"]
55
+ st.success(f"💰 Predicted Sales Revenue: **${predicted_sales:,.2f}**")
56
+ st.info(f"This prediction is for a {Product_Type} product in a {Store_Size} {Store_Type} located in {Store_Location_City_Type}.")
57
+ else:
58
+ st.error(f"Error in API request: Status Code {response.status_code}")
59
+ st.error(f"Response: {response.text}")
60
+ except requests.exceptions.RequestException as e:
61
+ st.error(f"Error connecting to API: {str(e)}")
62
+ st.info("Please ensure your backend API is deployed and the URL is correct.")
63
+
64
+ # Batch Prediction
65
+ st.subheader("Batch Prediction")
66
+ st.write("Upload a CSV file with product and store features to get predictions for multiple combinations.")
67
+
68
+ file = st.file_uploader("Upload CSV file", type=["csv"])
69
+ if file is not None:
70
+ # Display preview of uploaded file
71
+ df_preview = pd.read_csv(file)
72
+ st.write("Preview of uploaded file:")
73
+ st.dataframe(df_preview.head())
74
+
75
+ if st.button("Predict for Batch", type='primary'):
76
+ # Replace with your Hugging Face backend space URL
77
+ api_url = "https://<----user-name---->-<---repo name--->.hf.space/v1/salesbatch" # Enter user name and space name
78
+ try:
79
+ files = {"file": (file.name, file, "text/csv")}
80
+ response = requests.post(api_url, files=files, timeout=60)
81
+ if response.status_code == 200:
82
+ result = response.json()
83
+ result_df = pd.DataFrame(result)
84
+ st.header("Batch Prediction Results")
85
+ st.dataframe(result_df)
86
+
87
+ # Download button
88
+ csv = result_df.to_csv(index=False).encode('utf-8')
89
+ st.download_button(
90
+ label="Download Predictions as CSV",
91
+ data=csv,
92
+ file_name="predictions.csv",
93
+ mime="text/csv"
94
+ )
95
+ else:
96
+ st.error(f"Error in API request: Status Code {response.status_code}")
97
+ st.error(f"Response: {response.text}")
98
+ except requests.exceptions.RequestException as e:
99
+ st.error(f"Error connecting to API: {str(e)}")
100
+ st.info("Please ensure your backend API is deployed and the URL is correct.")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas==2.2.2
2
+ requests==2.28.1
3
+ streamlit==1.43.2