Spaces:
Sleeping
Sleeping
| import os | |
| # β Force Streamlit to use /tmp/.streamlit at runtime | |
| os.environ["STREAMLIT_CONFIG_DIR"] = "/tmp/.streamlit" | |
| os.makedirs("/tmp/.streamlit", exist_ok=True) | |
| # Optional: create config if missing | |
| config_path = "/tmp/.streamlit/config.toml" | |
| if not os.path.exists(config_path): | |
| with open(config_path, "w") as f: | |
| f.write("[server]\nheadless = true\nport = 7860\nenableCORS = false\n" | |
| "enableXsrfProtection = false\naddress = \"0.0.0.0\"") | |
| import streamlit as st | |
| import requests | |
| st.title("π SuperKart Sales Prediction") | |
| st.subheader("Enter Product Details") | |
| # Product inputs | |
| product_id = st.text_input("Product ID (e.g., FD1234)") | |
| product_weight = st.number_input("Product Weight", min_value=0.0, step=0.1) | |
| product_sugar = st.selectbox("Sugar Content", ["low sugar", "regular", "no sugar"]) | |
| product_area = st.number_input("Allocated Display Area Ratio", min_value=0.0, step=0.01) | |
| product_type = st.selectbox("Product Type", [ | |
| "meat", "snack foods", "hard drinks", "dairy", "canned", "soft drinks", | |
| "health and hygiene", "baking goods", "bread", "breakfast", "frozen foods", | |
| "fruits and vegetables", "household", "seafood", "starchy foods", "others" | |
| ]) | |
| product_mrp = st.number_input("Product MRP", min_value=0.0, step=0.1) | |
| # Store inputs | |
| store_id = st.text_input("Store ID (e.g., STR001)") | |
| store_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, step=1) | |
| store_size = st.selectbox("Store Size", ["high", "medium", "low"]) | |
| store_city = st.selectbox("Store City Type", ["Tier 1", "Tier 2", "Tier 3"]) | |
| store_type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type 1", "Supermarket Type 2", "Food Mart"]) | |
| store_age = 2025 - store_year | |
| # Backend endpoint | |
| # backend_url = "https://huggingface.co/spaces/keerthas/superkart-api/predict" | |
| backend_url = "https://keerthas-superkart-api.hf.space/predict" | |
| if st.button("Predict Sales"): | |
| input_data = { | |
| "Product_Id": product_id, | |
| "Product_Weight": product_weight, | |
| "Product_Sugar_Content": product_sugar, | |
| "Product_Allocated_Area": product_area, | |
| "Product_Type": product_type, | |
| "Product_MRP": product_mrp, | |
| "Store_Id": store_id, | |
| "Store_Establishment_Year": store_year, | |
| "Store_Size": store_size, | |
| "Store_Location_City_Type": store_city, | |
| "Store_Type": store_type, | |
| "Store_Age": store_age | |
| } | |
| try: | |
| response = requests.post(backend_url, json=input_data) | |
| if response.status_code == 200: | |
| result = response.json() | |
| if "prediction" in result: | |
| st.success(f"π° Predicted Sales: {result['prediction']:.2f}") | |
| else: | |
| st.error(f"Backend Error: {result}") | |
| else: | |
| st.error(f"β Request Failed: {response.text}") | |
| except Exception as e: | |
| st.error(f"Error: {e}") | |