Download app.py from Na-Rajan/MLProject: direct link, hf CLI and curl.
- Browser
- Download file 2.49 kB
-
https://huggingface.co/spaces/Na-Rajan/MLProject/resolve/main/app.py
- Command line
-
hf download hf://spaces/Na-Rajan/MLProject/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Na-Rajan/MLProject/resolve/main/app.py
2.49 kB
| # Streamlit frontend that collects product/store details and calls the Flask backend API | |
| import streamlit as st | |
| import requests | |
| # Backend URL: within the shared Docker network, containers reach each other | |
| # by container name. Defaults to the container name used when running the | |
| # backend container (see deployment instructions). | |
| BACKEND_URL = os.environ.get("BACKEND_URL", "http://superkart-backend:7860") | |
| st.set_page_config(page_title="SuperKart Sales Forecasting", layout="centered") | |
| st.title("SuperKart Sales Forecasting") | |
| st.write("Enter the product and store details below to forecast sales revenue.") | |
| # ----- Input widgets ----- | |
| product_weight = st.number_input("Product Weight", min_value=0.0, value=12.66, step=0.1) | |
| product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"]) | |
| product_allocated_area = st.number_input( | |
| "Product Allocated Area", min_value=0.0, max_value=1.0, value=0.027, step=0.001, format="%.3f" | |
| ) | |
| product_mrp = st.number_input("Product MRP", min_value=0.0, value=117.08, step=0.1) | |
| store_size = st.selectbox("Store Size", ["High", "Medium", "Small"]) | |
| store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"]) | |
| store_type = st.selectbox( | |
| "Store Type", | |
| ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Supermarket Type3", "Food Mart"], | |
| ) | |
| product_id_char = st.selectbox("Product Id Prefix", ["FD", "DR", "NC"]) | |
| store_age_years = st.number_input("Store Age (Years)", min_value=0, value=16, step=1) | |
| product_type_category = st.selectbox("Product Type Category", ["Perishables", "Non Perishables"]) | |
| if st.button("Predict Sales"): | |
| payload = { | |
| "Product_Weight": product_weight, | |
| "Product_Sugar_Content": product_sugar_content, | |
| "Product_Allocated_Area": product_allocated_area, | |
| "Product_MRP": product_mrp, | |
| "Store_Size": store_size, | |
| "Store_Location_City_Type": store_location_city_type, | |
| "Store_Type": store_type, | |
| "Product_Id_char": product_id_char, | |
| "Store_Age_Years": store_age_years, | |
| "Product_Type_Category": product_type_category, | |
| } | |
| try: | |
| response = requests.post(f"{BACKEND_URL}/v1/predict", json=payload) | |
| response.raise_for_status() | |
| prediction = response.json()["predicted_Product_Store_Sales_Total"] | |
| st.success(f"Predicted Sales: {prediction}") | |
| except Exception as e: | |
| st.error(f"Error while calling the backend API: {e}") | |