Spaces:
Runtime error
Runtime error
File size: 1,901 Bytes
4cd2f8b |
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 |
import streamlit as st
import pandas as pd
import requests
# Streamlit UI for Customer Churn Prediction
st.title("Sales Prediction App")
st.write("This tool predicts SupeKaet Sales. Enter the required information below.")
# Model Choice
model_choice = st.selectbox(
"Select Model",
options=["dt", "xgb"],
format_func=lambda x: "Decision Tree" if x == "dt" else "XGBoost"
)
# Collect user input based on dataset columns
product_weight = st.number_input("Product Weight", min_value=0.0)
sugar = st.selectbox("Sugar Content", [0, 1, 2])
area = st.number_input("Allocated Area", min_value=0.0)
product_type = st.number_input("Product Type Code", min_value=0)
mrp = st.number_input("Product MRP", min_value=0.0)
store_size = st.selectbox("Store Size Code", [0, 1, 2])
city = st.selectbox("City Type Code", [0, 1, 2])
store_type = st.number_input("Store Type Code", min_value=0)
store_age = st.number_input("Store Age", min_value=0)
# Convert categorical inputs to match model training
sample = {
"model": model_choice,
"Product_Weight": product_weight,
"Product_Sugar_Content": sugar,
"Product_Allocated_Area": area,
"Product_Type": product_type,
"Product_MRP": mrp,
"Store_Size": store_size,
"Store_Location_City_Type": city,
"Store_Type": store_type,
"Store_Age": store_age
}
if st.button("Predict", type='primary'):
response = requests.post("https://Lokiiparihar-Sample.hf.space/predict", json=sample) # enter user name and space name before running the cell
if response.status_code == 200:
result = response.json()
sales_prediction = result["Prediction"] # Extract only the value
st.write(f"Based on the information provided, the sale is likely to {sales_prediction}.")
else:
st.error("Error in API request")
# Run the Flask app in debug mode
if __name__ == '__main__':
app.run(debug=True)
|