| import streamlit as st |
| import pandas as pd |
| import requests |
|
|
| |
| st.title("Superkart Product Sales Price Prediction") |
|
|
| |
| st.subheader("Online Prediction") |
|
|
| |
| product_weight = st.number_input("Product Weight (kg)", min_value=0.0, step=0.1, value=1.0) |
| allocated_area = st.number_input("Product Allocated Area (sq ft)", min_value=0.0, step=0.1, value=10.0) |
| product_mrp = st.number_input("Product MRP ($)", min_value=0.0, step=0.1, value=100.0) |
| store_year = st.number_input("Store Establishment Year", min_value=1990, max_value=2025, step=1, value=2010) |
| product_type = st.selectbox("Product Type", ["Snack Foods", "Soft Drinks", "Household", "Frozen Foods", "Fruits and Vegetables", "Others"]) |
| store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"]) |
| product_sugar_content = st.selectbox("Product Sugar Content", ["Low", "Normal", "High"]) |
| store_size = st.selectbox("Store Size", ["Small", "Medium", "High"]) |
| store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Grocery Store"]) |
|
|
| |
| input_data = pd.DataFrame([{ |
| 'Product_Weight': product_weight, |
| 'Product_Allocated_Area': allocated_area, |
| 'Product_MRP': product_mrp, |
| 'Store_Establishment_Year': store_year, |
| 'Product_Sugar_Content': product_sugar_content, |
| 'Product_Type': product_type, |
| 'Store_Size': store_size, |
| 'Store_Location_City_Type': store_location_city_type, |
| 'Store_Type': store_type |
| }]) |
|
|
| |
| if st.button("Predict"): |
| response = requests.post( |
| "https://shak3232-sk-backend.hf.space/v1/sales", |
| json=input_data.to_dict(orient='records')[0] |
| ) |
| if response.status_code == 200: |
| prediction = response.json()['Sales Prediction Price (in dollars)'] |
| st.success(f"Predicted Sales Price: ${prediction}") |
| else: |
| st.error("Error making prediction. Please try again.") |
|
|
| |
| st.subheader("Batch Prediction") |
|
|
| |
| uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"]) |
|
|
| |
| if uploaded_file is not None: |
| if st.button("Predict Batch"): |
| files = {"file": uploaded_file.getvalue()} |
| response = requests.post( |
| "https://shak3232-sk-backend.hf.space/v1/salesbatch", |
| files={"file": uploaded_file} |
| ) |
| if response.status_code == 200: |
| predictions = response.json() |
| st.success("Batch predictions completed!") |
| st.json(predictions) |
| else: |
| st.error("Error making batch prediction.") |
|
|