Download streamlit_app.py from Nohafx/Streamlit: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/spaces/Nohafx/Streamlit/resolve/main/streamlit_app.py
- Command line
-
hf download hf://spaces/Nohafx/Streamlit/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/Nohafx/Streamlit/resolve/main/streamlit_app.py
2.02 kB
| import streamlit as st | |
| import requests | |
| API_URL = "https://nohafx-superkart-predictor.hf.space/predict" | |
| st.title("π SuperKart Product Sales Predictor") | |
| st.write("Enter product and store details to predict sales.") | |
| product_weight = st.number_input("Product Weight", min_value=0.0, value=12.5) | |
| product_sugar = st.selectbox("Product Sugar Content", ["Low Fat", "Regular", "Low Sugar"]) | |
| product_area = st.number_input("Product Allocated Area", min_value=0.0, max_value=1.0, value=0.05) | |
| product_type = st.selectbox("Product Type", [ | |
| "Snack Foods", "Dairy", "Fruits and Vegetables", | |
| "Frozen Foods", "Household", "Baking Goods", | |
| "Canned", "Health and Hygiene", "Soft Drinks", | |
| "Meat", "Breads", "Hard Drinks", "Others", | |
| "Starchy Foods", "Breakfast", "Seafood" | |
| ]) | |
| product_mrp = st.number_input("Product MRP", min_value=0.0, value=150.75) | |
| store_size = st.selectbox("Store Size", ["Small", "Medium", "High"]) | |
| store_location = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"]) | |
| store_type = st.selectbox("Store Type", [ | |
| "Supermarket Type1", "Supermarket Type2", | |
| "Supermarket Type3", "Grocery Store" | |
| ]) | |
| store_age = st.number_input("Store Age (Years)", min_value=0, value=15) | |
| if st.button("π Predict Sales"): | |
| input_data = { | |
| "Product_Weight": product_weight, | |
| "Product_Sugar_Content": product_sugar, | |
| "Product_Allocated_Area": product_area, | |
| "Product_Type": product_type, | |
| "Product_MRP": product_mrp, | |
| "Store_Size": store_size, | |
| "Store_Location_City_Type": store_location, | |
| "Store_Type": store_type, | |
| "Store_Age": store_age | |
| } | |
| try: | |
| response = requests.post(API_URL, json=input_data) | |
| if response.status_code == 200: | |
| prediction = response.json()["prediction"] | |
| st.success(f"β Predicted Sales: **${prediction:,.2f}**") | |
| else: | |
| st.error(f"β Error: {response.text}") | |
| except Exception as e: | |
| st.error(f"β Connection Error: {str(e)}") | |