SagarAtHf commited on
Commit
9616ff9
·
verified ·
1 Parent(s): f962402

Upload Streamlit frontend files

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +111 -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,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import requests
4
+ import json
5
+ import pandas as pd
6
+
7
+ # --- Page Configuration ---
8
+ st.set_page_config(page_title='SuperKart Sales Revenue Forecaster', layout='wide')
9
+ st.title('SuperKart Sales Revenue Forecaster')
10
+
11
+ # --- Backend API URL ---
12
+ # Make sure to update this with your deployed Flask API URL
13
+ # During local development, it might be 'http://localhost:5000/forecast_revenue'
14
+ # For Hugging Face Space, it will be the URL of your deployed backend space, e.g., 'https://<your-space-id>.hf.space/forecast_revenue'
15
+ BACKEND_URL = 'https://sagarathf-superkart.hf.space/v1/forecastrevenue' # API URL for POST
16
+
17
+ st.markdown("""
18
+ This application predicts the total sales revenue for a product in a given store.
19
+ Please fill in the details below to get a sales forecast.
20
+ """)
21
+
22
+ # --- Input Widgets for Features ---
23
+
24
+ st.subheader('Product Details')
25
+ col1, col2, col3 = st.columns(3)
26
+
27
+ with col1:
28
+ product_weight = st.number_input('Product Weight (kg)', min_value=0.1, max_value=50.0, value=10.0, step=0.1)
29
+ product_sugar_content = st.selectbox(
30
+ 'Product Sugar Content',
31
+ ['Low Sugar', 'Regular', 'No Sugar', 'Others']
32
+ )
33
+
34
+ with col2:
35
+ product_allocated_area = st.number_input('Product Allocated Area Ratio', min_value=0.001, max_value=0.5, value=0.05, step=0.001, format="%.3f")
36
+ product_type = st.selectbox(
37
+ 'Product Type',
38
+ ['Dairy', 'Soft Drinks', 'Meat', 'Fruits and Vegetables', 'Household',
39
+ 'Baking Goods', 'Snack Foods', 'Frozen Foods', 'Breakfast',
40
+ 'Health and Hygiene', 'Hard Drinks', 'Canned', 'Breads',
41
+ 'Starchy Foods', 'Others', 'Seafood']
42
+ )
43
+
44
+ with col3:
45
+ product_mrp = st.number_input('Product MRP (Max. Retail Price)', min_value=10.0, max_value=500.0, value=150.0, step=1.0)
46
+
47
+ st.subheader('Store Details')
48
+ col4, col5, col6 = st.columns(3)
49
+
50
+ with col4:
51
+ store_id = st.selectbox(
52
+ 'Store ID',
53
+ ['OUT003', 'OUT002', 'OUT001', 'OUT004']
54
+ )
55
+ store_establishment_year = st.number_input('Store Establishment Year', min_value=1950, max_value=2024, value=2000, step=1)
56
+
57
+ with col5:
58
+ store_size = st.selectbox(
59
+ 'Store Size',
60
+ ['Medium', 'High', 'Small']
61
+ )
62
+ store_location_city_type = st.selectbox(
63
+ 'Store Location City Type',
64
+ ['Tier 1', 'Tier 2', 'Tier 3']
65
+ )
66
+
67
+ with col6:
68
+ store_type = st.selectbox(
69
+ 'Store Type',
70
+ ['Departmental Store', 'Supermarket Type1', 'Food Mart', 'Supermarket Type2']
71
+ )
72
+
73
+
74
+ # --- Prediction Button and Logic ---
75
+ if st.button('Predict Sales Revenue'):
76
+ # Collect input data into a dictionary
77
+ input_data = {
78
+ "Product_Weight": product_weight,
79
+ "Product_Sugar_Content": product_sugar_content,
80
+ "Product_Allocated_Area": product_allocated_area,
81
+ "Product_Type": product_type,
82
+ "Product_MRP": product_mrp,
83
+ "Store_Id": store_id,
84
+ "Store_Establishment_Year": store_establishment_year,
85
+ "Store_Size": store_size,
86
+ "Store_Location_City_Type": store_location_city_type,
87
+ "Store_Type": store_type
88
+ }
89
+
90
+ # Display collected data (for debugging purposes)
91
+ st.json(input_data)
92
+
93
+ try:
94
+ # Send POST request to the backend API
95
+ response = requests.post(BACKEND_URL, json=input_data)
96
+
97
+ # Check if the request was successful
98
+ if response.status_code == 200:
99
+ prediction_result = response.json()
100
+ predicted_sales = prediction_result.get('predicted_sales')
101
+ if predicted_sales is not None:
102
+ st.success(f"Predicted Sales Revenue: &#8377;{predicted_sales:,.2f}")
103
+ else:
104
+ st.error("Prediction result not found in the API response.")
105
+ else:
106
+ st.error(f"Error from backend API: {response.status_code} - {response.text}")
107
+
108
+ except requests.exceptions.ConnectionError:
109
+ st.error("Could not connect to the backend API. Please ensure the API is running and the URL is correct.")
110
+ except Exception as e:
111
+ st.error(f"An unexpected error occurred: {e}")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit==1.43.2
2
+ requests==2.32.3
3
+ pandas==2.2.2