aibtus commited on
Commit
4602f5c
·
verified ·
1 Parent(s): 7b590c6

Upload 2 files

Browse files

My updates for link front end to back end

Files changed (2) hide show
  1. streamlit_app.py +95 -0
  2. streamlit_requirements.txt +3 -0
streamlit_app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # streamlit_app.py
2
+
3
+ import streamlit as st
4
+ import pandas as pd
5
+ import requests
6
+
7
+ # ----------------- CONFIGURATION -----------------
8
+ # CRITICAL: REPLACE THIS PLACEHOLDER URL with your actual deployed Docker Space URL
9
+ API_URL = "https://aibtus.ut.aiml.hf.space/predict"
10
+
11
+ # Define static categorical options (MUST match preprocessing categories)
12
+ CATEGORIES = {
13
+ 'Product_Sugar_Content': ['no sugar', 'low sugar', 'regular'],
14
+ 'Store_Size': ['Low', 'Medium', 'High'],
15
+ 'Store_Location_City_Type': ['Tier 1', 'Tier 2', 'Tier 3'],
16
+ 'Store_Type': ['Supermarket Type 1', 'Supermarket Type 2', 'Supermarket Type 3', 'Food Mart'],
17
+ 'Product_Type': ['Snack Foods', 'Dairy', 'Baking Goods', 'Health and Hygiene', 'Frozen Foods', 'Others',
18
+ 'Soft Drinks', 'Household', 'Meat', 'Fruits and Vegetables', 'Breads', 'Breakfast',
19
+ 'Hard Drinks', 'Starchy Foods', 'Seafood', 'Canned'],
20
+ 'Product_Category_Simplified': ['FD', 'DR', 'NC']
21
+ }
22
+
23
+ FEATURE_COLS = [
24
+ 'Product_Weight', 'Product_Sugar_Content', 'Product_Allocated_Area',
25
+ 'Product_Type', 'Product_MRP', 'Store_Size',
26
+ 'Store_Location_City_Type', 'Store_Type', 'Store_Age',
27
+ 'Product_Category_Simplified'
28
+ ]
29
+
30
+ # ----------------- APP INTERFACE -----------------
31
+
32
+ st.set_page_config(page_title="SuperKart Sales Forecaster", layout="wide")
33
+ st.title(" SuperKart Sales Forecasting Tool")
34
+
35
+ with st.form("sales_prediction_form"):
36
+ st.header("Product Attributes")
37
+
38
+ col1, col2, col3 = st.columns(3)
39
+
40
+ product_weight = col1.number_input("Product Weight (kg)", min_value=1.0, max_value=20.0, value=10.0, step=0.1)
41
+ product_mrp = col2.number_input("Product MRP (₹)", min_value=10.0, max_value=300.0, value=150.0, step=1.0)
42
+ product_allocated_area = col3.number_input("Product Allocated Area", min_value=0.0, max_value=1.0, value=0.07, step=0.01)
43
+
44
+ product_type = col1.selectbox("Product Type", options=CATEGORIES['Product_Type'])
45
+ product_sugar_content = col2.selectbox("Product Sugar Content", options=CATEGORIES['Product_Sugar_Content'])
46
+ product_category_simplified = col3.selectbox("Product Category (FD/DR/NC)", options=CATEGORIES['Product_Category_Simplified'])
47
+
48
+ st.header("Store Attributes")
49
+
50
+ col4, col5, col6 = st.columns(3)
51
+
52
+ store_type = col4.selectbox("Store Type", options=CATEGORIES['Store_Type'])
53
+ store_location_city_type = col5.selectbox("Store Location City Type", options=CATEGORIES['Store_Location_City_Type'])
54
+ store_size = col6.selectbox("Store Size", options=CATEGORIES['Store_Size'])
55
+
56
+ store_age = st.slider("Store Age (Years)", min_value=5, max_value=35, value=10)
57
+
58
+
59
+ submitted = st.form_submit_button("Forecast Sales")
60
+
61
+ if submitted:
62
+ input_data = {
63
+ 'Product_Weight': product_weight,
64
+ 'Product_Sugar_Content': product_sugar_content,
65
+ 'Product_Allocated_Area': product_allocated_area,
66
+ 'Product_Type': product_type,
67
+ 'Product_MRP': product_mrp,
68
+ 'Store_Size': store_size,
69
+ 'Store_Location_City_Type': store_location_city_type,
70
+ 'Store_Type': store_type,
71
+ 'Store_Age': float(store_age),
72
+ 'Product_Category_Simplified': product_category_simplified
73
+ }
74
+
75
+ payload = [input_data]
76
+
77
+ try:
78
+ st.info(f"Sending request to API at: {API_URL}...")
79
+ response = requests.post(API_URL, json=payload, timeout=15)
80
+
81
+ if response.status_code == 200:
82
+ result = response.json()
83
+ if result['status'] == 'success':
84
+ st.success(f" **Forecast Complete!**")
85
+ st.metric(label="Predicted Sales Revenue", value=f"₹{result['predicted_sales_revenue']:,.2f}")
86
+ st.balloons()
87
+ else:
88
+ st.error(f"Prediction API Error: {result.get('error', 'Unknown error')}")
89
+ else:
90
+ st.error(f"**API Connection Error** (Status {response.status_code}): Check API URL and Docker logs.")
91
+
92
+ except requests.exceptions.Timeout:
93
+ st.error("**Connection Failed:** Request timed out (15s). The Docker API might be slow or unreachable.")
94
+ except Exception as e:
95
+ st.error(f"An unexpected error occurred: {e}")
streamlit_requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit==1.36.0
2
+ pandas==2.2.2
3
+ requests==2.32.3