Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,95 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import pickle
|
| 3 |
-
import numpy as np
|
| 4 |
-
|
| 5 |
-
# Load model and scaler
|
| 6 |
-
with open("marketing_model.pkl", "rb") as f:
|
| 7 |
-
model = pickle.load(f)
|
| 8 |
-
|
| 9 |
-
with open("scaler.pkl", "rb") as f:
|
| 10 |
-
scaler = pickle.load(f)
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def predict_campaign(
|
| 14 |
-
income,
|
| 15 |
-
kidhome,
|
| 16 |
-
teenhome,
|
| 17 |
-
recency,
|
| 18 |
-
wines,
|
| 19 |
-
fruits,
|
| 20 |
-
meat,
|
| 21 |
-
fish,
|
| 22 |
-
sweets,
|
| 23 |
-
gold,
|
| 24 |
-
web_purchases,
|
| 25 |
-
store_purchases
|
| 26 |
-
):
|
| 27 |
-
|
| 28 |
-
# Convert inputs to float
|
| 29 |
-
income = float(income)
|
| 30 |
-
kidhome = float(kidhome)
|
| 31 |
-
teenhome = float(teenhome)
|
| 32 |
-
recency = float(recency)
|
| 33 |
-
wines = float(wines)
|
| 34 |
-
fruits = float(fruits)
|
| 35 |
-
meat = float(meat)
|
| 36 |
-
fish = float(fish)
|
| 37 |
-
sweets = float(sweets)
|
| 38 |
-
gold = float(gold)
|
| 39 |
-
web_purchases = float(web_purchases)
|
| 40 |
-
store_purchases = float(store_purchases)
|
| 41 |
-
|
| 42 |
-
# Calculate total spending
|
| 43 |
-
total_spending = wines + fruits + meat + fish + sweets + gold
|
| 44 |
-
|
| 45 |
-
# Feature array
|
| 46 |
-
features = np.array([
|
| 47 |
-
income,
|
| 48 |
-
kidhome,
|
| 49 |
-
teenhome,
|
| 50 |
-
recency,
|
| 51 |
-
wines,
|
| 52 |
-
fruits,
|
| 53 |
-
meat,
|
| 54 |
-
fish,
|
| 55 |
-
sweets,
|
| 56 |
-
gold,
|
| 57 |
-
web_purchases,
|
| 58 |
-
store_purchases,
|
| 59 |
-
total_spending
|
| 60 |
-
]).reshape(1, -1)
|
| 61 |
-
|
| 62 |
-
# Scale features
|
| 63 |
-
features = scaler.transform(features)
|
| 64 |
-
|
| 65 |
-
# Prediction
|
| 66 |
-
prediction = model.predict(features)[0]
|
| 67 |
-
|
| 68 |
-
if prediction == 1:
|
| 69 |
-
return "✅ Customer will likely accept the marketing campaign"
|
| 70 |
-
else:
|
| 71 |
-
return "❌ Customer is unlikely to accept the marketing campaign"
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
interface = gr.Interface(
|
| 75 |
-
fn=predict_campaign,
|
| 76 |
-
inputs=[
|
| 77 |
-
gr.Number(label="Income"),
|
| 78 |
-
gr.Number(label="Kidhome"),
|
| 79 |
-
gr.Number(label="Teenhome"),
|
| 80 |
-
gr.Number(label="Recency"),
|
| 81 |
-
gr.Number(label="Wine Spending"),
|
| 82 |
-
gr.Number(label="Fruit Spending"),
|
| 83 |
-
gr.Number(label="Meat Spending"),
|
| 84 |
-
gr.Number(label="Fish Spending"),
|
| 85 |
-
gr.Number(label="Sweet Spending"),
|
| 86 |
-
gr.Number(label="Gold Spending"),
|
| 87 |
-
gr.Number(label="Web Purchases"),
|
| 88 |
-
gr.Number(label="Store Purchases"),
|
| 89 |
-
],
|
| 90 |
-
outputs=gr.Textbox(label="Prediction Result"),
|
| 91 |
-
title="Sales Analytics & Marketing Automation",
|
| 92 |
-
description="Predict whether a customer will accept a marketing campaign."
|
| 93 |
-
)
|
| 94 |
-
|
| 95 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|