Spaces:
Sleeping
Sleeping
| import pandas as pd | |
| import pickle as pkl | |
| import smtplib | |
| from email.mime.multipart import MIMEMultipart | |
| from email.mime.text import MIMEText | |
| import streamlit as st | |
| import base64 | |
| def set_light_background(image_file): | |
| with open(image_file, "rb") as image: | |
| encoded = base64.b64encode(image.read()).decode() | |
| ext = image_file.split('.')[-1] | |
| st.markdown( | |
| f""" | |
| <style> | |
| .stApp {{ | |
| background: linear-gradient( | |
| rgba(255, 255, 255, 0.7), | |
| rgba(255, 255, 255, 0.7) | |
| ), | |
| url("data:image/{ext};base64,{encoded}"); | |
| background-size: cover; | |
| background-repeat: no-repeat; | |
| background-attachment: fixed; | |
| }} | |
| h1, h2, h3, h4, h5, h6 {{ | |
| color: #1a1a1a; | |
| }} | |
| .stApp {{ | |
| color: #202020; | |
| }} | |
| </style> | |
| """, | |
| unsafe_allow_html=True | |
| ) | |
| set_light_background("musicbg.jpg") | |
| # 🎯 Add Image at the Top | |
| st.image("inno.jpg", use_container_width=True,width=500) | |
| st.markdown( | |
| f"<h1 style='text-align: center;'>Subscription & Business Analytics</h1>", | |
| unsafe_allow_html=True) | |
| # 🎯 Add Image at the Top | |
| st.image("music.png", use_container_width=True,width=500) | |
| st.header("Business and Data Understanding") | |
| st.subheader("Business Statements") | |
| st.write(""" | |
| - The business problem statement is **music streaming service** that offers" | |
| " different subscription plans (Free, Premium, Family). The main goal is to analyze" | |
| " user behavior and predict customer churn—whether a user will leave the platform .""") | |
| st.subheader("Business Objective") | |
| st.write(""" | |
| - Identify key factors contributing to customer churn (e.g., subscription type, engagement metrics, payment method). | |
| - Improve customer retention strategies by targeting at-risk users with promotions, better recommendations, or engagement campaigns. | |
| - Enhance user experience by understanding listening habits, subscription patterns, and customer service interactions. | |
| - Optimize marketing efforts to encourage conversions from free users to premium plans.""") | |
| st.subheader("Business Constraints") | |
| st.write(""" | |
| - Business constraints are limitations or restrictions that affect decision-making, | |
| operations, or strategic planning within a business. They can include: | |
| - Financial Constraints: Budget limitations, funding availability, or cost-cutting measures. | |
| - Time Constraints: Project deadlines, time-to-market pressures, or regulatory timelines. | |
| - Resource Constraints: Limited workforce, technology, or raw materials. | |
| - Legal & Compliance Constraints: Industry regulations, data privacy laws (e.g., GDPR), or contractual obligations. | |
| - Market Constraints: Customer demand, competition, or economic conditions. | |
| - Technical Constraints: Software/hardware limitations, system integrations, or scalability issues. | |
| - Operational Constraints: Supply chain restrictions, production capabilities, or logistics limitations.""") | |
| st.header("Data Understanding") | |
| st.write(""" | |
| - *Dataset Size:* 125000 rows × 20 columns. | |
| - *Data Types:* float64(3), int64(11), object(4) | |
| - *Data Features:*'age', 'location', 'subscription_type', 'payment_plan', | |
| 'num_subscription_pauses', 'customer_service_inquiries', 'signup_date', | |
| 'weekly_hours', 'average_session_length' 'song_skip_rate', | |
| 'weekly_songs_played', 'weekly_unique_songs', 'num_favorite_artists', | |
| 'num_platform_friends', 'num_playlists_created', 'num_shared_playlists', | |
| 'notifications_clicked', 'churned'. """) | |
| st.write(r"https://www.kaggle.com/competitions/streaming-subscription-churn-model/overview") | |
| st.write("Demo data") | |
| data = pd.read_csv("data.csv") | |
| st.write(data) | |
| dff = st.file_uploader("Upload File:") | |
| with open("pipe.pkl","rb") as file: | |
| pipe = pkl.load(file) | |
| with open("model.pkl","rb") as file: | |
| model = pkl.load(file) | |
| if dff: | |
| df =pd.read_csv(dff) | |
| req = df | |
| test = pipe.transform(req) | |
| predicted = model.predict(test) | |
| df["churned"] = predicted | |
| st.table(df[["customer_id","churned"]]) | |
| ans = { | |
| 0: { | |
| "name": "name", | |
| "email": "email", | |
| "mail": { | |
| "subject": "🎶 Discover New Music You'll Love, name!", | |
| "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" | |
| } | |
| }, | |
| 1: { | |
| "name": "name", | |
| "email": "email", | |
| "mail": { | |
| "subject": "We Miss You, Moon! Come Back for More Music & Family Fun!", | |
| "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" | |
| } | |
| } | |
| } | |
| st.bar_chart(df["churned"].value_counts()) | |
| mails_data = pd.DataFrame(ans).T | |
| if st.button('Send Mail'): | |
| for i in df.index: | |
| cust_id = df.iloc[i]["customer_id"] | |
| name = df.iloc[i]["name"] | |
| email_id = df.iloc[i]["email"] | |
| pred = df.iloc[i]["churned"] | |
| sender_email = "moon24012407@gmail.com" | |
| receiver_email = email_id | |
| password = "rjig xxky lwfc xkcb" | |
| # Email content | |
| subject = mails_data.iloc[pred]['mail']['subject'].replace('name',name) | |
| body = mails_data.iloc[pred]['mail']['body'].replace('name',name) | |
| # Create the email | |
| message = MIMEMultipart() | |
| message["From"] = sender_email | |
| message["To"] = receiver_email | |
| message["Subject"] = subject | |
| message.attach(MIMEText(body, "plain")) | |
| # Set up the SMTP server and send the email | |
| try: | |
| server = smtplib.SMTP("smtp.gmail.com", 587) | |
| server.starttls() # Secure the connection | |
| server.login(sender_email, password) | |
| server.sendmail(sender_email, receiver_email, message.as_string()) | |
| server.quit() | |
| st.write(f"{cust_id} : Email sent successfully!") | |
| except Exception as e: | |
| st.write(f"{cust_id} : Failed to send email: {e}") | |
| st.write("Accurace : 0.82328") |