prahalya commited on
Commit
00b1acc
·
verified ·
1 Parent(s): 7034270

Delete app.py

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