prahalya commited on
Commit
906acc7
·
verified ·
1 Parent(s): 5c04739

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -90
app.py CHANGED
@@ -1,90 +1,90 @@
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
- st.write(r"https://www.kaggle.com/competitions/streaming-subscription-churn-model/overview")
9
-
10
- st.write("Demo Data:")
11
- data = pd.read_csv('data.csv')
12
- st.table(data)
13
-
14
- dff = st.file_uploader("Upload File:")
15
-
16
-
17
-
18
- with open("pipe.pkl","rb") as file:
19
- pipe = pkl.load(file)
20
-
21
- with open("model.pkl","rb") as file:
22
- model = pkl.load(file)
23
-
24
- if dff:
25
- df =pd.read_csv(dff)
26
- req = df
27
- test = pipe.transform(req)
28
-
29
- predicted = model.predict(test)
30
- df["churned"] = predicted
31
-
32
- st.table(df[["customer_id","churned"]])
33
-
34
- ans = {
35
- 0: {
36
- "name": "name",
37
- "email": "email",
38
- "mail": {
39
- "subject": "🎶 Discover New Music You'll Love, name!",
40
- "body": "Hey name,\n\nWe noticed you have a fantastic taste for music, exploring tons of unique songs every week! To help you find even more tracks you'll love, we've put together some recommendations just for you.\n\nBased on your listening habits, we think you might enjoy:\n\n* **Daily Mixes:** Personalized playlists refreshed daily with music we think you'll be excited about.\n* **New Music Friday:** Stay up-to-date with the freshest releases from your favorite genres and artists.\n* **Genre Playlists:** Dive deeper into genres you love or explore 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"
41
- }
42
- },
43
- 1: {
44
- "name": "name",
45
- "email": "email",
46
- "mail": {
47
- "subject": "We Miss You, Moon! Come Back for More Music & Family Fun!",
48
- "body": "Hi name,\n\nWe've noticed you've been away from our music platform, and we wanted to reach out and see if everything is alright. 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, we'd like to offer you a special **30-day free trial** to re-engage with all the latest music, podcasts, and features you might have missed. Rediscover millions of songs, create new playlists, 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"
49
- }
50
- }
51
- }
52
-
53
- st.bar_chart(df["churned"].value_counts())
54
-
55
- mails_data = pd.DataFrame(ans).T
56
-
57
- if st.button('Send Mail'):
58
- for i in df.index:
59
- cust_id = df.iloc[i]["customer_id"]
60
- name = df.iloc[i]["name"]
61
- email_id = df.iloc[i]["email"]
62
- pred = df.iloc[i]["churned"]
63
-
64
- sender_email = "moon24012407@gmail.com"
65
- receiver_email = email_id
66
- password = "rjig xxky lwfc xkcb"
67
-
68
- # Email content
69
- subject = mails_data.iloc[pred]['mail']['subject'].replace('name',name)
70
-
71
- body = mails_data.iloc[pred]['mail']['body'].replace('name',name)
72
-
73
-
74
- # Create the email
75
- message = MIMEMultipart()
76
- message["From"] = sender_email
77
- message["To"] = receiver_email
78
- message["Subject"] = subject
79
- message.attach(MIMEText(body, "plain"))
80
-
81
- # Set up the SMTP server and send the email
82
- try:
83
- server = smtplib.SMTP("smtp.gmail.com", 587)
84
- server.starttls() # Secure the connection
85
- server.login(sender_email, password)
86
- server.sendmail(sender_email, receiver_email, message.as_string())
87
- server.quit()
88
- st.write(f"{cust_id} : Email sent successfully!")
89
- except Exception as e:
90
- st.write(f"{cust_id} : Failed to send email: {e}")
 
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
+ st.write(r"https://www.kaggle.com/competitions/streaming-subscription-churn-model/overview")
9
+
10
+ st.write("Demo Data:")
11
+ data = pd.read_csv('data.csv')
12
+ st.write(data)
13
+
14
+ dff = st.file_uploader("Upload File:")
15
+
16
+
17
+
18
+ with open("pipe.pkl","rb") as file:
19
+ pipe = pkl.load(file)
20
+
21
+ with open("model.pkl","rb") as file:
22
+ model = pkl.load(file)
23
+
24
+ if dff:
25
+ df =pd.read_csv(dff)
26
+ req = df
27
+ test = pipe.transform(req)
28
+
29
+ predicted = model.predict(test)
30
+ df["churned"] = predicted
31
+
32
+ st.table(df[["customer_id","churned"]])
33
+
34
+ ans = {
35
+ 0: {
36
+ "name": "name",
37
+ "email": "email",
38
+ "mail": {
39
+ "subject": "🎶 Discover New Music You'll Love, name!",
40
+ "body": "Hey name,\n\nWe noticed you have a fantastic taste for music, exploring tons of unique songs every week! To help you find even more tracks you'll love, we've put together some recommendations just for you.\n\nBased on your listening habits, we think you might enjoy:\n\n* **Daily Mixes:** Personalized playlists refreshed daily with music we think you'll be excited about.\n* **New Music Friday:** Stay up-to-date with the freshest releases from your favorite genres and artists.\n* **Genre Playlists:** Dive deeper into genres you love or explore 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"
41
+ }
42
+ },
43
+ 1: {
44
+ "name": "name",
45
+ "email": "email",
46
+ "mail": {
47
+ "subject": "We Miss You, Moon! Come Back for More Music & Family Fun!",
48
+ "body": "Hi name,\n\nWe've noticed you've been away from our music platform, and we wanted to reach out and see if everything is alright. 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, we'd like to offer you a special **30-day free trial** to re-engage with all the latest music, podcasts, and features you might have missed. Rediscover millions of songs, create new playlists, 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"
49
+ }
50
+ }
51
+ }
52
+
53
+ st.bar_chart(df["churned"].value_counts())
54
+
55
+ mails_data = pd.DataFrame(ans).T
56
+
57
+ if st.button('Send Mail'):
58
+ for i in df.index:
59
+ cust_id = df.iloc[i]["customer_id"]
60
+ name = df.iloc[i]["name"]
61
+ email_id = df.iloc[i]["email"]
62
+ pred = df.iloc[i]["churned"]
63
+
64
+ sender_email = "moon24012407@gmail.com"
65
+ receiver_email = email_id
66
+ password = "rjig xxky lwfc xkcb"
67
+
68
+ # Email content
69
+ subject = mails_data.iloc[pred]['mail']['subject'].replace('name',name)
70
+
71
+ body = mails_data.iloc[pred]['mail']['body'].replace('name',name)
72
+
73
+
74
+ # Create the email
75
+ message = MIMEMultipart()
76
+ message["From"] = sender_email
77
+ message["To"] = receiver_email
78
+ message["Subject"] = subject
79
+ message.attach(MIMEText(body, "plain"))
80
+
81
+ # Set up the SMTP server and send the email
82
+ try:
83
+ server = smtplib.SMTP("smtp.gmail.com", 587)
84
+ server.starttls() # Secure the connection
85
+ server.login(sender_email, password)
86
+ server.sendmail(sender_email, receiver_email, message.as_string())
87
+ server.quit()
88
+ st.write(f"{cust_id} : Email sent successfully!")
89
+ except Exception as e:
90
+ st.write(f"{cust_id} : Failed to send email: {e}")