Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import pandas as pd | |
| import requests | |
| # Set the title of the Streamlit app | |
| st.title("Superkart Sales Forecasting") | |
| # Section for online prediction | |
| st.subheader("Sales Forecast") | |
| # Define the input fields | |
| product_weight = st.number_input("Product Weight", min_value=0.0) | |
| sugar_content = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"]) | |
| allocated_area = st.number_input("Allocated Area", min_value=0.0) | |
| product_type = st.selectbox("Product Type", sorted([ | |
| "Frozen Foods", "Dairy", "Canned", "Baking Goods", "Health and Hygiene", "Snack Foods", | |
| "Meat", "Household", "Fruits and Vegetables", "Breads", "Hard Drinks", "Soft Drinks", | |
| "Breakfast", "Starchy Foods", "Seafood", "Others" | |
| ])) | |
| product_mrp = st.number_input("Product MRP", min_value=0.0) | |
| store_id = st.text_input("Store ID") | |
| store_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2100) | |
| store_size = st.selectbox("Store Size", ["Small", "Medium", "High"]) | |
| city_type = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"]) | |
| store_type = st.selectbox("Store Type", [ | |
| "Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart" | |
| ]) | |
| # Collect all inputs into a DataFrame | |
| input_dict = { | |
| "Product_Weight": product_weight, | |
| "Product_Sugar_Content": sugar_content, | |
| "Product_Allocated_Area": allocated_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": city_type, | |
| "Store_Type": store_type | |
| } | |
| print("Input dict______", input_dict) | |
| input_df = pd.DataFrame([input_dict]) | |
| # Make prediction when the "Predict" button is clicked | |
| if st.button("Predict Sales"): | |
| response = requests.post("https://dutta2arnab-SuperKartSalesPredictionBackend.hf.space/v1/sales_forecast", json=input_df.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 Sales 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 Sales Batch"): | |
| response = requests.post("https://dutta2arnab-SuperKartSalesPredictionBackend.hf.space/v1/sales_forecast_batch", 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.") | |