Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,148 +0,0 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
import pickle as pkl
|
| 3 |
-
import smtplib
|
| 4 |
-
from email.mime.multipart import MIMEMultipart
|
| 5 |
-
from email.mime.text import MIMEText
|
| 6 |
-
import streamlit as st
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# 🎯 Add Image at the Top
|
| 11 |
-
st.image("inno.jpg", use_container_width=True,width=300)
|
| 12 |
-
st.markdown(
|
| 13 |
-
f"<h1 style='text-align: center;'>Subscription & Business Analytics</h1>",
|
| 14 |
-
unsafe_allow_html=True)
|
| 15 |
-
# 🎯 Add Image at the Top
|
| 16 |
-
st.image("music.png", use_container_width=True,width=300)
|
| 17 |
-
|
| 18 |
-
st.header("Business and Data Understanding")
|
| 19 |
-
st.subheader("Business Statements")
|
| 20 |
-
st.write("""
|
| 21 |
-
- The business problem statement is **music streaming service** that offers"
|
| 22 |
-
" different subscription plans (Free, Premium, Family). The main goal is to analyze"
|
| 23 |
-
" user behavior and predict customer churn—whether a user will leave the platform .""")
|
| 24 |
-
|
| 25 |
-
st.subheader("Business Objective")
|
| 26 |
-
st.write("""
|
| 27 |
-
- Identify key factors contributing to customer churn (e.g., subscription type, engagement metrics, payment method).
|
| 28 |
-
- Improve customer retention strategies by targeting at-risk users with promotions, better recommendations, or engagement campaigns.
|
| 29 |
-
- Enhance user experience by understanding listening habits, subscription patterns, and customer service interactions.
|
| 30 |
-
- Optimize marketing efforts to encourage conversions from free users to premium plans.""")
|
| 31 |
-
|
| 32 |
-
st.subheader("Business Constraints")
|
| 33 |
-
st.write("""
|
| 34 |
-
- Business constraints are limitations or restrictions that affect decision-making,
|
| 35 |
-
operations, or strategic planning within a business. They can include:
|
| 36 |
-
|
| 37 |
-
- Financial Constraints: Budget limitations, funding availability, or cost-cutting measures.
|
| 38 |
-
- Time Constraints: Project deadlines, time-to-market pressures, or regulatory timelines.
|
| 39 |
-
- Resource Constraints: Limited workforce, technology, or raw materials.
|
| 40 |
-
- Legal & Compliance Constraints: Industry regulations, data privacy laws (e.g., GDPR), or contractual obligations.
|
| 41 |
-
- Market Constraints: Customer demand, competition, or economic conditions.
|
| 42 |
-
- Technical Constraints: Software/hardware limitations, system integrations, or scalability issues.
|
| 43 |
-
- Operational Constraints: Supply chain restrictions, production capabilities, or logistics limitations.""")
|
| 44 |
-
|
| 45 |
-
st.header("Data Understanding")
|
| 46 |
-
st.write("""
|
| 47 |
-
- *Dataset Size:* 125000 rows × 20 columns.
|
| 48 |
-
- *Data Types:* float64(3), int64(11), object(4)
|
| 49 |
-
- *Data Features:*'age', 'location', 'subscription_type', 'payment_plan',
|
| 50 |
-
'num_subscription_pauses', 'customer_service_inquiries', 'signup_date',
|
| 51 |
-
'weekly_hours', 'average_session_length' 'song_skip_rate',
|
| 52 |
-
'weekly_songs_played', 'weekly_unique_songs', 'num_favorite_artists',
|
| 53 |
-
'num_platform_friends', 'num_playlists_created', 'num_shared_playlists',
|
| 54 |
-
'notifications_clicked', 'churned'. """)
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
st.write(r"https://www.kaggle.com/competitions/streaming-subscription-churn-model/overview")
|
| 59 |
-
st.write("Demo data")
|
| 60 |
-
data = pd.read_csv("data.csv")
|
| 61 |
-
st.write(data)
|
| 62 |
-
dff = st.file_uploader("Upload File:")
|
| 63 |
-
|
| 64 |
-
with open("pipe.pkl","rb") as file:
|
| 65 |
-
pipe = pkl.load(file)
|
| 66 |
-
|
| 67 |
-
with open("model.pkl","rb") as file:
|
| 68 |
-
model = pkl.load(file)
|
| 69 |
-
|
| 70 |
-
if dff:
|
| 71 |
-
df =pd.read_csv(dff)
|
| 72 |
-
req = df
|
| 73 |
-
test = pipe.transform(req)
|
| 74 |
-
|
| 75 |
-
predicted = model.predict(test)
|
| 76 |
-
df["churned"] = predicted
|
| 77 |
-
|
| 78 |
-
st.table(df[["customer_id","churned"]])
|
| 79 |
-
|
| 80 |
-
ans = {
|
| 81 |
-
0: {
|
| 82 |
-
"name": "name",
|
| 83 |
-
"email": "email",
|
| 84 |
-
"mail": {
|
| 85 |
-
"subject": "🎶 Discover New Music You'll Love, name!",
|
| 86 |
-
"body": "Hey name,\n\nWe noticed you have a fantastic taste for music, "
|
| 87 |
-
"exploring tons of unique songs every week! To help you find even more tracks you'll love, "
|
| 88 |
-
"we've put together some recommendations just for you.\n\nBased on your listening habits, "
|
| 89 |
-
"we think you might enjoy:\n\n* **Daily Mixes:** Personalized playlists refreshed daily with music "
|
| 90 |
-
"we think you'll be excited about.\n* **New Music Friday:** Stay up-to-date with the freshest releases "
|
| 91 |
-
"from your favorite genres and artists.\n* **Genre Playlists:** Dive deeper into genres you love or explore "
|
| 92 |
-
"something completely new.\n\nReady to discover your next favorite song? Click here to explore: [Link to App/Music Platform]\n\nHappy listening,\nYour Music Team"
|
| 93 |
-
}
|
| 94 |
-
},
|
| 95 |
-
1: {
|
| 96 |
-
"name": "name",
|
| 97 |
-
"email": "email",
|
| 98 |
-
"mail": {
|
| 99 |
-
"subject": "We Miss You, Moon! Come Back for More Music & Family Fun!",
|
| 100 |
-
"body": "Hi name,\n\nWe've noticed you've been away from our music platform, "
|
| 101 |
-
"and we wanted to reach out and see if everything is alright."
|
| 102 |
-
" We truly value you as a Family plan subscriber and want to ensure you and your family are getting the most out of our service.\n\nTo welcome you back, "
|
| 103 |
-
"we'd like to offer you a special **30-day free trial** to re-engage with all the latest music, podcasts, "
|
| 104 |
-
"and features you might have missed. Rediscover millions of songs, create new playlists, "
|
| 105 |
-
"and share the joy of music with your family again.\n\nClick here to reactivate your free trial and start listening: [Link to Reactivation Page]\n\nWe hope to see you back soon!\n\nBest regards,\nYour Music Team"
|
| 106 |
-
}
|
| 107 |
-
}
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
st.bar_chart(df["churned"].value_counts())
|
| 111 |
-
|
| 112 |
-
mails_data = pd.DataFrame(ans).T
|
| 113 |
-
|
| 114 |
-
if st.button('Send Mail'):
|
| 115 |
-
for i in df.index:
|
| 116 |
-
cust_id = df.iloc[i]["customer_id"]
|
| 117 |
-
name = df.iloc[i]["name"]
|
| 118 |
-
email_id = df.iloc[i]["email"]
|
| 119 |
-
pred = df.iloc[i]["churned"]
|
| 120 |
-
|
| 121 |
-
sender_email = "moon24012407@gmail.com"
|
| 122 |
-
receiver_email = email_id
|
| 123 |
-
password = "rjig xxky lwfc xkcb"
|
| 124 |
-
|
| 125 |
-
# Email content
|
| 126 |
-
subject = mails_data.iloc[pred]['mail']['subject'].replace('name',name)
|
| 127 |
-
|
| 128 |
-
body = mails_data.iloc[pred]['mail']['body'].replace('name',name)
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
# Create the email
|
| 132 |
-
message = MIMEMultipart()
|
| 133 |
-
message["From"] = sender_email
|
| 134 |
-
message["To"] = receiver_email
|
| 135 |
-
message["Subject"] = subject
|
| 136 |
-
message.attach(MIMEText(body, "plain"))
|
| 137 |
-
|
| 138 |
-
# Set up the SMTP server and send the email
|
| 139 |
-
try:
|
| 140 |
-
server = smtplib.SMTP("smtp.gmail.com", 587)
|
| 141 |
-
server.starttls() # Secure the connection
|
| 142 |
-
server.login(sender_email, password)
|
| 143 |
-
server.sendmail(sender_email, receiver_email, message.as_string())
|
| 144 |
-
server.quit()
|
| 145 |
-
st.write(f"{cust_id} : Email sent successfully!")
|
| 146 |
-
except Exception as e:
|
| 147 |
-
st.write(f"{cust_id} : Failed to send email: {e}")
|
| 148 |
-
st.write("Accurace : 0.82328")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|