| import streamlit as st
|
| import pandas as pd
|
| import numpy as np
|
| import joblib
|
|
|
|
|
| st.set_page_config(page_title="ABC+ Product Segmentation", page_icon="📊", layout="wide")
|
|
|
|
|
| @st.cache_resource
|
| def load_assets():
|
| model = joblib.load('ABC_Analysis_modeli.pkl')
|
| scaler = joblib.load('scaler.pkl')
|
| return model, scaler
|
|
|
| try:
|
| model, scaler = load_assets()
|
| except Exception as e:
|
| st.error(f"Model files could not be loaded: {e}")
|
|
|
|
|
| st.sidebar.header("About the Project")
|
| st.sidebar.info(
|
| "This application uses product data from the Wish platform to "
|
| "segment products using the K-Means algorithm. "
|
| "It determines the strategic value of products based on ABC Analysis logic."
|
| )
|
|
|
| st.sidebar.divider()
|
| st.sidebar.warning(
|
| "**Note on Currency:** All monetary values are processed in **Euro (€)** "
|
| "to ensure analytical consistency across the dataset."
|
| )
|
|
|
|
|
| st.title("📊 Smart Product Segmentation & ABC+ Analysis")
|
| st.markdown("""
|
| Enter the data of a new product to instantly learn which segment it belongs to and
|
| its strategic importance for the business.
|
| """)
|
|
|
|
|
| col1, col2 = st.columns(2)
|
|
|
| with col1:
|
| st.subheader("💰 Financial Data")
|
| price = st.number_input("Selling Price (€)", min_value=0.0, value=10.0)
|
| units_sold = st.number_input("Units Sold", min_value=0, value=1000)
|
|
|
| revenue = price * units_sold
|
| st.write(f"**Calculated Total Revenue:** {revenue:,.2f} €")
|
|
|
| with col2:
|
| st.subheader("⭐ Performance Data")
|
| rating = st.slider("Product Rating", 1.0, 5.0, 4.0)
|
| discount_pct = st.slider("Discount Rate (%)", 0, 100, 20)
|
|
|
|
|
| if st.button("Segment the Product"):
|
|
|
|
|
| input_data = np.array([[
|
| np.log1p(revenue),
|
| np.log1p(units_sold),
|
| rating,
|
| price,
|
| discount_pct
|
| ]])
|
|
|
|
|
| scaled_data = scaler.transform(input_data)
|
|
|
|
|
| cluster = model.predict(scaled_data)[0]
|
|
|
|
|
| mapping = {
|
| 3: {'cat': 'A+ (Superstars)', 'color': 'gold', 'desc': 'The most valuable, high-revenue, and popular products of the store.'},
|
| 0: {'cat': 'A (High Quality)', 'color': 'green', 'desc': 'High customer satisfaction and products that generate regular income.'},
|
| 1: {'cat': 'B (Campaign Oriented)', 'color': 'orange', 'desc': 'Mid-segment products usually sold with high discounts.'},
|
| 2: {'cat': 'C (Low Performance)', 'color': 'red', 'desc': 'Products with low sales volume or weak ratings; risky products.'}
|
| }
|
|
|
| result = mapping.get(cluster, {'cat': 'Unknown', 'color': 'grey', 'desc': 'No specific description available.'})
|
|
|
|
|
| st.divider()
|
| st.subheader(f"Predicted Segment: :{result['color']}[{result['cat']}]")
|
| st.write(f"**Description:** {result['desc']}")
|
|
|
|
|
| st.metric(label="Target Segment Alignment", value=result['cat'], delta="Analysis Completed")
|
|
|
|
|
| st.divider()
|
| st.caption("Developer: Elif Şensöz Beşiktepe | Data Science Project 2026")
|
|
|