Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import requests | |
| st.title("Sales Total Price Prediction") | |
| st.subheader("Single Prediction") | |
| # Single-Prediction Inputs | |
| # Store_Id and Product_Id are excluded from input as they are only required for identification, not useful for one prediction | |
| product_weight = st.number_input("Product Weight", step=0.5) | |
| product_sugar_content = st.selectbox("Product Sugar Content", ["No Sugar", "Low Sugar", "Regular"]) | |
| product_allocated_area = st.number_input("Product Allocated Area", step=0.05) | |
| product_type = st.selectbox("Product Type", [ | |
| "Frozen Foods", | |
| "Dairy", | |
| "Canned", | |
| "Baking Goods", | |
| "Health and Hygiene", | |
| "Snack Foods", | |
| "Meat", | |
| "Household", | |
| "Hard Drinks", | |
| "Fruits and Vegetables", | |
| "Breads", | |
| "Soft Drinks", | |
| "Breakfast", | |
| "Others", | |
| "Starchy Foods", | |
| "Seafood" | |
| ]) | |
| product_mrp = st.number_input("Product MRP", step=0.5) | |
| store_establishment_year = int(st.number_input("Store Establishment Year", step=1)) | |
| store_size = st.selectbox("Store Size", ["Small", "Medium", "High"]) | |
| store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"]) | |
| store_type = st.selectbox("Store Type", ["Departmental Store", "Food Mart", "Supermarket Type1", "Supermarket Type2"]) | |
| if st.button("Predict"): | |
| with st.spinner("Predicting"): | |
| response = requests.post("https://UTAIML-SalesTotalPredictionBackend.hf.space/api/total", json= | |
| { | |
| "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 | |
| } | |
| ) | |
| if response.status_code == 200: | |
| # Get and output prediction | |
| prediction = response.json()["Prediction"] | |
| st.success(f"Prediction: {prediction}") | |
| else: | |
| st.error("Something went wrong!") | |
| # Batch Prediction | |
| st.subheader("Batch Prediction") | |
| st.subheader("Accepting Product_Id, Store_Id, and all single-prediction keys.") | |
| # Get CSV file | |
| csv_file = st.file_uploader("Upload CSV file", type=["csv"]) | |
| if csv_file is not None: | |
| if st.button("Batch Predict"): | |
| with st.spinner("Predicting"): | |
| response = requests.post("https://UTAIML-SalesTotalPredictionBackend.hf.space/api/totals", files={"file": csv_file}) | |
| if response.status_code == 200: | |
| # Get and output predictions | |
| predictions = response.json() | |
| st.success("Completed Batch Predictions!") | |
| st.write(predictions) | |
| else: | |
| st.error("Something went wrong!") | |