Spaces:
Sleeping
Sleeping
| import os | |
| import pandas as pd | |
| import streamlit as st | |
| from io import StringIO | |
| # Persistent file path for the dataset | |
| DATA_FILE_PATH = "customer-churn-prediction.csv" | |
| # Page Title | |
| st.markdown("<h1 style='text-align:center; color:white;'>customer-churn-prediction Data Set</h1>", unsafe_allow_html=True) | |
| # Function to load the dataset from the disk | |
| def load_dataset(): | |
| if os.path.exists(DATA_FILE_PATH): | |
| return pd.read_csv(DATA_FILE_PATH) | |
| else: | |
| return None | |
| # Load or reload the dataset into session state if not already done | |
| if "dataset" not in st.session_state: | |
| st.session_state["dataset"] = load_dataset() | |
| # File uploader widget to upload a new dataset | |
| uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"]) | |
| if uploaded_file is not None: | |
| # Read the uploaded CSV file into a pandas DataFrame | |
| df = pd.read_csv(uploaded_file) | |
| # Save the dataset permanently to disk | |
| df.to_csv(DATA_FILE_PATH, index=False) | |
| # Update session state | |
| st.session_state["dataset"] = df | |
| # Display success message | |
| st.success(f"Dataset uploaded and saved permanently as {DATA_FILE_PATH}!") | |
| # Access the dataset from session state | |
| df = st.session_state.get("dataset") | |
| if df is not None: | |
| st.subheader("Dataset Preview:") | |
| st.write(df, use_container_width=True) | |
| st.subheader("Info of the Dataset:") | |
| buffer = StringIO() | |
| df.info(buf=buffer) | |
| st.text(buffer.getvalue()) | |
| st.subheader("Dataset Shape (Rows, Columns):") | |
| st.write(df.shape) | |
| st.markdown('''**Dataset :** | |
| | **Feature** | **Description** | **Example** | | |
| |-------------------------|--------------------------------------------------------------------|------------------------------| | |
| | **creditscore** | Credit score of the customer, typically ranging from 300 to 850. | 750 | |
| | **geography** | Country or region of the customer. | France, Germany, Spain | |
| | **gender** | Gender of the customer. | Male, Female | |
| |**age** | Age of the customer. | 45 | |
| |**tenure** | Number of years the customer has been with the organization. | 5 | |
| |**balance** | Account balance of the customer. |125000.50 | |
| |**numofproducts** | Number of products the customer is using with the company. | 2 | |
| |**hascrcard** | Indicates whether the customer has a credit card |(1 - Yes, 0 - No). 1 | |
| |**isactivemember** | Indicates whether the customer is an active member |(1 - Yes, 0 - No). 0 | |
| |**estimatedsalary** |Annual estimated salary of the customer. |70000.00 | |
| |**exited Target variable**| Indicates if the customer has exited |(1 - Yes, 0 - No). 1 | |
| ''') | |
| else: | |
| st.info("No dataset found. Please upload a CSV file.") | |
| # Define the URL of the background image (use your own image URL) | |
| background_image_url = "https://cdn-uploads.huggingface.co/production/uploads/67445925102349e867c92342/jeRCGDG126mCBSEL_yzoh.png" | |
| # Apply custom CSS for the background image and overlay | |
| st.markdown( | |
| f""" | |
| <style> | |
| .stApp {{ | |
| background-image: url("{background_image_url}"); | |
| background-size: cover; | |
| background-position: center; | |
| height: 100vh; | |
| }} | |
| /* Semi-transparent overlay */ | |
| .stApp::before {{ | |
| content: ""; | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 100%; | |
| background: rgba(0, 0, 0, 0.4); | |
| z-index: -1; | |
| }} | |
| /* Styling the content to ensure text visibility */ | |
| .stMarkdown {{ | |
| color: white; | |
| font-size: 100px; | |
| }} | |
| </style> | |
| """, | |
| unsafe_allow_html=True | |
| ) | |
| if st.button("Previous ⏮️"): | |
| st.switch_page("pages/0_Problem-Statement_and_Aim.py") | |
| if st.button("Next ⏭️"): | |
| st.switch_page("pages/2_Data_CLeaning_and_Preprocessing.py") |