prahalya commited on
Commit
9e46575
·
verified ·
1 Parent(s): 970fa52

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -149
app.py DELETED
@@ -1,149 +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 Streaming Service", 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
-
57
- st.write("Demo Data:")
58
- data = pd.read_csv('data.csv')
59
- st.table(data)
60
-
61
- dff = st.file_uploader("Upload File:")
62
-
63
-
64
-
65
- with open("pipe.pkl","rb") as file:
66
- pipe = pkl.load(file)
67
-
68
- with open("model.pkl","rb") as file:
69
- model = pkl.load(file)
70
-
71
- if dff:
72
- df =pd.read_csv(dff)
73
- req = df
74
- test = pipe.transform(req)
75
-
76
- predicted = model.predict(test)
77
- df["churned"] = predicted
78
-
79
- st.table(df[["customer_id","churned"]])
80
-
81
- ans = {
82
- 0: {
83
- "name": "name",
84
- "email": "email",
85
- "mail": {
86
- "subject": "🎶 Discover New Music You'll Love, name!",
87
- "body": "Hey name,\n\nWe noticed you have a fantastic taste for music, "
88
- "exploring tons of unique songs every week! To help you find even more tracks you'll love, "
89
- "we've put together some recommendations just for you.\n\nBased on your listening habits, "
90
- "we think you might enjoy:\n\n* **Daily Mixes:** Personalized playlists refreshed daily with music "
91
- "we think you'll be excited about.\n* **New Music Friday:** Stay up-to-date with the freshest releases "
92
- "from your favorite genres and artists.\n* **Genre Playlists:** Dive deeper into genres you love or explore "
93
- "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"
94
- }
95
- },
96
- 1: {
97
- "name": "name",
98
- "email": "email",
99
- "mail": {
100
- "subject": "We Miss You, Moon! Come Back for More Music & Family Fun!",
101
- "body": "Hi name,\n\nWe've noticed you've been away from our music platform, "
102
- "and we wanted to reach out and see if everything is alright."
103
- " 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, "
104
- "we'd like to offer you a special **30-day free trial** to re-engage with all the latest music, podcasts, "
105
- "and features you might have missed. Rediscover millions of songs, create new playlists, "
106
- "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"
107
- }
108
- }
109
- }
110
-
111
- st.bar_chart(df["churned"].value_counts())
112
-
113
- mails_data = pd.DataFrame(ans).T
114
-
115
- if st.button('Send Mail'):
116
- for i in df.index:
117
- cust_id = df.iloc[i]["customer_id"]
118
- name = df.iloc[i]["name"]
119
- email_id = df.iloc[i]["email"]
120
- pred = df.iloc[i]["churned"]
121
-
122
- sender_email = "moon24012407@gmail.com"
123
- receiver_email = email_id
124
- password = "rjig xxky lwfc xkcb"
125
-
126
- # Email content
127
- subject = mails_data.iloc[pred]['mail']['subject'].replace('name',name)
128
-
129
- body = mails_data.iloc[pred]['mail']['body'].replace('name',name)
130
-
131
-
132
- # Create the email
133
- message = MIMEMultipart()
134
- message["From"] = sender_email
135
- message["To"] = receiver_email
136
- message["Subject"] = subject
137
- message.attach(MIMEText(body, "plain"))
138
-
139
- # Set up the SMTP server and send the email
140
- try:
141
- server = smtplib.SMTP("smtp.gmail.com", 587)
142
- server.starttls() # Secure the connection
143
- server.login(sender_email, password)
144
- server.sendmail(sender_email, receiver_email, message.as_string())
145
- server.quit()
146
- st.write(f"{cust_id} : Email sent successfully!")
147
- except Exception as e:
148
- st.write(f"{cust_id} : Failed to send email: {e}")
149
- st.write("Accurace : 0.82328")