| import streamlit as st |
| import pandas as pd |
| import numpy as np |
| import pickle |
|
|
| |
| st.set_page_config(page_title="π― Direct Message Influence Predictor", layout="wide") |
|
|
| |
| st.markdown(""" |
| <style> |
| body { |
| background-color: #080808; |
| } |
| .stApp { |
| background-color: #080808; |
| } |
| .title-text { |
| color: #00FFFF; |
| font-size: 32px; |
| font-weight: bold; |
| } |
| .sidebar-title { |
| font-size: 18px; |
| font-weight: bold; |
| } |
| .feature-box { |
| background-color: #080808 ; |
| padding: 15px; |
| border-radius: 10px; |
| box-shadow: 0px 2px 6px rgba(0,0,0,0.1); |
| } |
| </style> |
| """, unsafe_allow_html=True) |
|
|
| |
| try: |
| with open("best_random_forest_model (1).pkl", "rb") as file: |
| model = pickle.load(file) |
| except FileNotFoundError: |
| st.error("β Model file 'best_random_forest_model (1).pkl' not found. Please make sure it is in the same directory as this app.") |
| st.stop() |
|
|
| |
| st.markdown('<div class="title-text">π― Coupon Influence Prediction</div>', unsafe_allow_html=True) |
| st.write("Fill in the customer data below to predict if the direct mail coupon was effective.") |
|
|
| |
| col1, col2 = st.columns([1, 1]) |
|
|
| with col1: |
| st.markdown("### π§Ύ Customer Input") |
| with st.form(key="predict_form"): |
| used_coupon = st.selectbox("Used Coupon After DM?", [0, 1]) |
| after_spend = st.number_input("Spend After DM ($)", min_value=0.0, format="%.2f") |
| after_units = st.number_input("Units After DM", min_value=0) |
| before_spend = st.number_input("Spend Before DM ($)", min_value=0.0, format="%.2f") |
| submit_button = st.form_submit_button("π Predict") |
|
|
| if submit_button: |
| input_data = pd.DataFrame([[used_coupon, after_spend, after_units, before_spend]], |
| columns=["used_coupon_after_dm", "after_spend", "after_units", "before_spend"]) |
| prediction = model.predict(input_data)[0] |
| proba = model.predict_proba(input_data)[0][prediction] |
|
|
| label = "β
Influenced by DM" if prediction == 1 else "β Not Influenced" |
| st.success(f"**Prediction:** {label}") |
| st.info(f"**Confidence:** {proba * 100:.2f}%") |
|
|
| with col2: |
| st.markdown("### π Feature Descriptions") |
| st.markdown(""" |
| <div class='feature-box'> |
| <ul> |
| <li><b>Used Coupon After DM?</b><br>Whether the customer used the direct mail (DM) coupon. <br><code>1 = Yes</code>, <code>0 = No</code></li><br> |
| <li><b>Spend After DM ($)</b><br>Total money the customer spent <b>after</b> receiving the direct mail coupon.</li><br> |
| <li><b>Units After DM</b><br>Number of items purchased <b>after</b> receiving the coupon.</li><br> |
| <li><b>Spend Before DM ($)</b><br>Total money spent <b>before</b> receiving the direct mail coupon.</li> |
| </ul> |
| </div> |
| """, unsafe_allow_html=True) |
|
|