Spaces:
No application file
No application file
| import streamlit as st | |
| import pandas as pd | |
| import requests | |
| # Set the title of the Streamlit app | |
| st.title("SuperKart Sales Forecast") | |
| # Section for online prediction | |
| st.subheader("Sales Prediction") | |
| # Collect user input for property features | |
| product_weight = st.number_input(("Product Weight") | |
| product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"]) | |
| product_allocated_area = st.number_input(("Product Allocated Area") | |
| product_type = st.selectbox("Product Type", ["Fruits and Vegetables", "Snack Foods", "Frozen Foods", "Dairy", "Household", "Baking Goods", "Canned", | |
| "Health and Hygiene", "Meat", "Soft Drinks", "Breads", "Hard Drinks", "Others", "Starchy Foods", "Breakfast", "Seafood"]) | |
| product_mrp = st.number_input(("Product MRP") | |
| store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, step=1) | |
| store_size = st.number_input("Store Size", min_value=0, step=1, value=1) | |
| store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"]) | |
| store_type = st.selectbox("Store Type", ["Food Mart", "Departmental Store", "Supermarket Type1", "Supermarket Type2" ]) | |
| # Convert user input into a DataFrame | |
| input_data = pd.DataFrame([{ | |
| 'product_weight': product_weight, | |
| 'product_sugar_content': product_sugar_content, | |
| 'product_allocated_area': product_allocated_area, | |
| 'product_type': product_type, | |
| 'product_mrp': product_mrp, | |
| 'store_establishment_year': store_establishment_year | |
| 'store_size': store_size, | |
| 'store_location_city_type': store_location_city_type, | |
| 'store_type': store_type | |
| }]) | |
| # Make prediction when the "Predict" button is clicked | |
| if st.button("Predict"): | |
| response = requests.post("https://aks2022-superkartsalesforecastbackend.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API | |
| if response.status_code == 200: | |
| prediction = response.json()['Predicted Price (in dollars)'] | |
| st.success(f"Predicted Rental Price (in dollars): {prediction}") | |
| else: | |
| st.error("Error making prediction.") | |
| # Section for batch prediction | |
| st.subheader("Batch Prediction") | |
| # Allow users to upload a CSV file for batch prediction | |
| uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"]) | |
| # Make batch prediction when the "Predict Batch" button is clicked | |
| if uploaded_file is not None: | |
| if st.button("Predict Batch"): | |
| response = requests.post("https://aks2022-superkartsalesforecastbackend.hf.space/v1/salesbatch", files={"file": uploaded_file}) # Send file to Flask API | |
| if response.status_code == 200: | |
| predictions = response.json() | |
| st.success("Batch predictions completed!") | |
| st.write(predictions) # Display the predictions | |
| else: | |
| st.error("Error making batch prediction.") | |