sales_analytics / app.py
Snigs98's picture
Upload app.py
a73c874 verified
import gradio as gr
import pickle
import numpy as np
# Load model and scaler
with open("marketing_model.pkl", "rb") as f:
model = pickle.load(f)
with open("scaler.pkl", "rb") as f:
scaler = pickle.load(f)
def predict_campaign(
education, marital_status, income, kidhome, teenhome, recency,
wines, fruits, meat, fish, sweets, gold,
deals, web, catalog, store, visits,
cmp3, cmp4, cmp5, cmp1, cmp2,
complain, cost_contact, revenue,
age
):
total_spending = wines + fruits + meat + fish + sweets + gold
features = np.array([
education, marital_status, income, kidhome, teenhome, recency,
wines, fruits, meat, fish, sweets, gold,
deals, web, catalog, store, visits,
cmp3, cmp4, cmp5, cmp1, cmp2,
complain, cost_contact, revenue,
age, total_spending
]).reshape(1, -1)
features = scaler.transform(features)
prediction = model.predict(features)[0]
if prediction == 1:
return "✅ Customer will accept the marketing campaign"
else:
return "❌ Customer will NOT accept the campaign"
interface = gr.Interface(
fn=predict_campaign,
inputs=[
gr.Number(label="Education"),
gr.Number(label="Marital Status"),
gr.Number(label="Income"),
gr.Number(label="Kidhome"),
gr.Number(label="Teenhome"),
gr.Number(label="Recency"),
gr.Number(label="Wine Spending"),
gr.Number(label="Fruit Spending"),
gr.Number(label="Meat Spending"),
gr.Number(label="Fish Spending"),
gr.Number(label="Sweet Spending"),
gr.Number(label="Gold Spending"),
gr.Number(label="Deals Purchases"),
gr.Number(label="Web Purchases"),
gr.Number(label="Catalog Purchases"),
gr.Number(label="Store Purchases"),
gr.Number(label="Web Visits Per Month"),
gr.Number(label="Accepted Campaign 3"),
gr.Number(label="Accepted Campaign 4"),
gr.Number(label="Accepted Campaign 5"),
gr.Number(label="Accepted Campaign 1"),
gr.Number(label="Accepted Campaign 2"),
gr.Number(label="Complain"),
gr.Number(label="Cost Contact"),
gr.Number(label="Revenue"),
gr.Number(label="Age"),
],
outputs=gr.Textbox(label="Prediction"),
title="Sales Analytics & Marketing Automation",
description="Predict whether a customer will accept a marketing campaign"
)
interface.launch()