HacksterT commited on
Commit
686d5ee
·
verified ·
1 Parent(s): 0204b12

Force upload new streamlit app - 1754762016

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +69 -0
src/streamlit_app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import json
4
+
5
+ # Page config
6
+ st.set_page_config(page_title="SuperKart Sales Forecasting", layout="wide")
7
+
8
+ # API URL - your working backend
9
+ API_BASE_URL = "https://hackstert-greatlearningproject.hf.space"
10
+
11
+ st.title("SuperKart Sales Forecasting")
12
+ st.write("Enter product details to get sales prediction")
13
+
14
+ # Simple form
15
+ with st.form("prediction_form"):
16
+ col1, col2 = st.columns(2)
17
+
18
+ with col1:
19
+ st.subheader("Product Info")
20
+ product_weight = st.number_input("Weight (kg)", value=12.5)
21
+ product_mrp = st.number_input("Price ($)", value=150.0)
22
+ product_sugar_content = st.selectbox("Sugar Content", ["Low Fat", "Regular"])
23
+ # product_type = st.selectbox("Product Type", ["Dairy", "Soft Drinks", "Meat", "Fruits and Vegetables", "Household", "Baking Goods", "Snack Foods", "Frozen Foods", "Breakfast", "Health and Hygiene", "Hard Drinks", "Canned", "Breads", "Starchy Foods", "Others", "Seafood"])
24
+ product_type = st.selectbox("Product Type", ["Dairy", "Soft Drinks", "Meat"])
25
+
26
+ with col2:
27
+ st.subheader("Store Info")
28
+ store_id = st.selectbox("Store ID", [f"OUT{str(i).zfill(3)}" for i in range(1, 11)])
29
+ store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
30
+ store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Supermarket Type3", "Grocery Store"])
31
+ store_location = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])
32
+ store_year = st.number_input("Establishment Year", value=2009)
33
+
34
+ if st.form_submit_button("Predict Sales"):
35
+ # Prepare data
36
+ data = {
37
+ "Product_Weight": product_weight,
38
+ "Product_MRP": product_mrp,
39
+ "Product_Sugar_Content": product_sugar_content,
40
+ "Product_Type": product_type,
41
+ "Store_Id": store_id,
42
+ "Store_Size": store_size,
43
+ "Store_Type": store_type,
44
+ "Store_Location_City_Type": store_location,
45
+ "Store_Establishment_Year": store_year
46
+ }
47
+
48
+ try:
49
+ # Call API
50
+ response = requests.post(f"{API_BASE_URL}/predict", json=data)
51
+
52
+ if response.status_code == 200:
53
+ result = response.json()
54
+ st.success(f"Predicted Sales: {result['prediction_formatted']}")
55
+ else:
56
+ st.error(f"API Error: {response.status_code}")
57
+ except Exception as e:
58
+ st.error(f"Connection Error: {str(e)}")
59
+
60
+ # Health check
61
+ if st.button("Check API Status"):
62
+ try:
63
+ response = requests.get(f"{API_BASE_URL}/")
64
+ if response.status_code == 200:
65
+ st.success("API is healthy!")
66
+ else:
67
+ st.error("API not responding")
68
+ except:
69
+ st.error("Cannot connect to API")