Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import requests | |
| # Set the title of the Streamlit app | |
| st.title("Total Sales Prediction App for SuperKart") | |
| # Section for online prediction | |
| st.subheader("Online Prediction") | |
| # Collect user input | |
| Product_Weight = st.number_input("Product Weight", min_value=4.0, max_value=22.0, step=0.01, value=4.0) | |
| Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.004, max_value=0.298, step=0.001, value=0.004) | |
| Product_MRP = st.number_input("Product MRP", min_value=31.0, max_value=266.0, step=0.01, value=31.0) | |
| Store_Establishment_Year = int(st.number_input("Store_Establishment_Year", min_value=1987, max_value=2009, step=1, value=2009)) | |
| Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low", "Regular", "Non Sugar"]) | |
| Product_Type = st.selectbox("Product Type", ["Fruits and Vegetables", "Dairy", "Baking Goods", "Others"]) | |
| Store_Id = st.selectbox("Store Id", ["OUT001", "OUT002", "OUT003", "OUT004"]) | |
| 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", "Supermarket Type1", "Supermarket Type2"]) | |
| # Convert user input into a DataFrame | |
| input_data = pd.DataFrame([{ | |
| 'Product_Weight': Product_Weight, | |
| 'Product_Allocated_Area': Product_Allocated_Area, | |
| 'Product_MRP': Product_MRP, | |
| 'cStore_Establishment_Year': Store_Establishment_Year, | |
| 'Product_Sugar_Content': Product_Sugar_Content, | |
| 'Product_Type': Product_Type, | |
| 'Store_Id': Store_Id, | |
| '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://RubeenaNouman-PredictionBackend.hf.space/v1/pred", 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 Sales Price (in dollars): {prediction}") | |
| else: | |
| st.error("Error making prediction.") | |