Spaces:
Sleeping
Sleeping
Update streamlit app
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108import streamlit as stimport requestsimport pandas as pdimport jsonfrom datetime import datetime# Page configurationst.set_page_config(page_title="SuperKart Sales Forecasting",page_icon="🛒",layout="wide")# API ConfigurationAPI_BASE_URL = "https://hackstert-greatlearningproject.hf.space"# Titlest.title("🛒 SuperKart Sales Forecasting System")st.write("Enter product and store details to get a sales forecast")# Helper function to make API callsdef call_api(endpoint, data=None, method="GET"):try:url = f"{API_BASE_URL}{endpoint}"if method == "GET":response = requests.get(url)elif method == "POST":response = requests.post(url, json=data)if response.status_code == 200:return response.json(), Noneelse:return None, f"API Error: {response.status_code}"except Exception as e:return None, f"Connection Error: {str(e)}"# Create input formwith st.form("prediction_form"):col1, col2 = st.columns(2)with col1:st.subheader("Product Information")product_weight = st.number_input("Product Weight (kg)", min_value=0.1, max_value=50.0, value=12.5)product_sugar_content = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar"])product_type = st.selectbox("Product Type", ["Dairy", "Soft Drinks", "Meat", "Fruits and Vegetables", "Household","Baking Goods", "Snack Foods", "Frozen Foods", "Breakfast"])product_mrp = st.number_input("Maximum Retail Price ($)", min_value=1.0, max_value=500.0, value=150.0)with col2:st.subheader("Store Information")store_id = st.selectbox("Store ID", [f"OUT{str(i).zfill(3)}" for i in range(1, 46)])store_establishment_year = st.number_input("Establishment Year", min_value=1985, max_value=2024, value=2009)store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])store_location_city_type = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Supermarket Type3","Grocery Store", "Departmental Store"])# Submit buttonsubmitted = st.form_submit_button("🔮 Predict Sales", type="primary")if submitted:# Prepare data for API callprediction_data = {"Product_Weight": product_weight,"Product_Sugar_Content": product_sugar_content,"Product_Type": product_type,"Product_MRP": product_mrp,"Store_Id": store_id,"Store_Establishment_Year": store_establishment_year,"Store_Size": store_size,"Store_Location_City_Type": store_location_city_type,"Store_Type": store_type}# Make API callwith st.spinner("Predicting sales..."):result, error = call_api("/predict", prediction_data, "POST")if result:st.success("Prediction completed successfully!")st.metric("Predicted Sales", result["prediction_formatted"])# Show additional detailswith st.expander("View Details"):st.write(f"Raw Prediction: ${result['prediction']:.2f}")st.write(f"Model Version: {result['model_version']}")st.write(f"Timestamp: {result['timestamp']}")else:st.error(f"Prediction failed: {error}")# API Health Check Sectionst.markdown("---")st.subheader("🏥 API Health Check")if st.button("Check API Status"):with st.spinner("Checking API health..."):result, error = call_api("/")if result:st.success("API is healthy!")st.write(f"Status: {result['status']}")st.write(f"Message: {result['message']}")else:st.error(f"API health check failed: {error}")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566import streamlit as stimport requestsimport json# Page configst.set_page_config(page_title="SuperKart Sales Forecasting", layout="wide")# API URL - your working backendAPI_BASE_URL = "https://hackstert-greatlearningproject.hf.space"st.title("SuperKart Sales Forecasting")st.write("Enter product details to get sales prediction")# Simple formwith st.form("prediction_form"):col1, col2 = st.columns(2)with col1:st.subheader("Product Info")product_weight = st.number_input("Weight (kg)", value=12.5)product_mrp = st.number_input("Price ($)", value=150.0)product_sugar_content = st.selectbox("Sugar Content", ["Low Sugar", "Regular"])product_type = st.selectbox("Product Type", ["Dairy", "Soft Drinks", "Meat", "Fruits and Vegetables"])with col2:st.subheader("Store Info")store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])store_type = st.selectbox("Store Type", ["Supermarket Type1", "Grocery Store"])store_location = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])store_year = st.number_input("Establishment Year", value=2009)if st.form_submit_button("Predict Sales"):# Prepare datadata = {"Product_Weight": product_weight,"Product_MRP": product_mrp,"Product_Sugar_Content": product_sugar_content,"Product_Type": product_type,"Store_Size": store_size,"Store_Type": store_type,"Store_Location_City_Type": store_location,"Store_Establishment_Year": store_year}try:# Call APIresponse = requests.post(f"{API_BASE_URL}/predict", json=data)if response.status_code == 200:result = response.json()st.success(f"Predicted Sales: {result['prediction_formatted']}")else:st.error(f"API Error: {response.status_code}")except Exception as e:st.error(f"Connection Error: {str(e)}")# Health checkif st.button("Check API Status"):try:response = requests.get(f"{API_BASE_URL}/")if response.status_code == 200:st.success("API is healthy!")else:st.error("API not responding")except:st.error("Cannot connect to API")
src/streamlit_app.py+41-83