Spaces:
Sleeping
Sleeping
Force upload new streamlit app - 1754761443
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768import streamlit as st
import requests
import json
# Page config
st.set_page_config(page_title="SuperKart Sales Forecasting", layout="wide")
# API URL - your working backend
API_BASE_URL = "https://hackstert-greatlearningproject.hf.space"
st.title("SuperKart Sales Forecasting")
st.write("Enter product details to get sales prediction")
# Simple form
with 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 Fat", "Regular"])
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"])
with col2:
st.subheader("Store Info")
store_id = st.selectbox("Store ID", [f"OUT{str(i).zfill(3)}" for i in range(1, 11)])
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Supermarket Type3", "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 data
data = {
"Product_Weight": product_weight,
"Product_MRP": product_mrp,
"Product_Sugar_Content": product_sugar_content,
"Product_Type": product_type,
"Store_Id": store_id,
"Store_Size": store_size,
"Store_Type": store_type,
"Store_Location_City_Type": store_location,
"Store_Establishment_Year": store_year
}
try:
# Call API
response = 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 check
if 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.pyAdded+68