File size: 3,173 Bytes
7a85880 8999842 7a85880 8999842 7a85880 107095a 7a85880 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import streamlit as st
import requests
import pandas as pd
import json
from datetime import datetime
st.title("SuperKart Sales Forecasting")
st.write("Enter the details of the product and store to get a sales forecast.")
# Input fields for the user to provide data
product_id = st.text_input("Product ID")
product_weight = st.number_input("Product Weight", value=10.0, format="%.2f")
product_sugar_content = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar', 'reg'])
product_allocated_area = st.number_input("Product Allocated Area", value=0.1, format="%.3f")
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", value=150.0, format="%.2f")
store_id = st.selectbox("Store ID", ['OUT004', 'OUT003', 'OUT001', 'OUT002'])
store_establishment_year = st.number_input("Store Establishment Year", value=2000, format="%d")
store_size = st.selectbox("Store Size", ['Medium', 'High', 'Small'])
store_location_city_type = st.selectbox("Store Location City Type", ['Tier 2', 'Tier 1', 'Tier 3'])
store_type = st.selectbox("Store Type", ['Supermarket Type2', 'Departmental Store', 'Supermarket Type1', 'Food Mart'])
# Create a dictionary with the input data
input_data = {
'Product_Id': product_id,
'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_Id': store_id,
'Store_Establishment_Year': store_establishment_year,
'Store_Size': store_size,
'Store_Location_City_Type': store_location_city_type,
'Store_Type': store_type
}
# Add feature engineering for Product_Category and Store_Age
current_year = datetime.now().year
input_data['Store_Age'] = current_year - input_data['Store_Establishment_Year']
input_data['Product_Category'] = input_data['Product_Id'][:2]
# Button to trigger prediction
if st.button("Predict Sales"):
# Hugging Face proxy URL for Flask backend
# Replace with the actual URL of your deployed backend API on Hugging Face Spaces
backend_url = "https://bhumitps-md-be.hf.space/predict"
try:
# Send a POST request to the backend API
response = requests.post(backend_url, json=[input_data]) # Send as a list of one data point
# Check if the request was successful
if response.status_code == 200:
predictions = response.json().get('predictions')
if predictions:
st.success(f"Predicted Sales: {predictions[0]:.2f}")
else:
st.error("Error: Could not retrieve predictions from the backend.")
else:
st.error(f"Error: Received status code {response.status_code} from the backend.")
st.error(f"Response: {response.text}")
except requests.exceptions.RequestException as e:
st.error(f"Error connecting to the backend API: {e}")
|