yamunagovindha commited on
Commit
30028ff
·
verified ·
1 Parent(s): 643a008

Create pages/1_Data_Card_and_Data_collection.py

Browse files
pages/pages/1_Data_Card_and_Data_collection.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pandas as pd
3
+ import streamlit as st
4
+ from io import StringIO
5
+
6
+ # Persistent file path for the dataset
7
+ DATA_FILE_PATH = "healthcare-dataset-stroke-data.csv"
8
+
9
+ # Page Title
10
+ st.markdown("<h1 style='text-align:center; color:white;'>healthcare-dataset</h1>", unsafe_allow_html=True)
11
+
12
+ # Function to load the dataset from the disk
13
+ def load_dataset():
14
+ if os.path.exists(DATA_FILE_PATH):
15
+ return pd.read_csv(DATA_FILE_PATH)
16
+ else:
17
+ return None
18
+
19
+ # Load or reload the dataset into session state if not already done
20
+ if "dataset" not in st.session_state:
21
+ st.session_state["dataset"] = load_dataset()
22
+
23
+ # File uploader widget to upload a new dataset
24
+ uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
25
+
26
+ if uploaded_file is not None:
27
+ # Read the uploaded CSV file into a pandas DataFrame
28
+ df = pd.read_csv(uploaded_file)
29
+
30
+ # Save the dataset permanently to disk
31
+ df.to_csv(DATA_FILE_PATH, index=False)
32
+
33
+ # Update session state
34
+ st.session_state["dataset"] = df
35
+
36
+ # Display success message
37
+ st.success(f"Dataset uploaded and saved permanently as {DATA_FILE_PATH}!")
38
+
39
+ # Access the dataset from session state
40
+ df = st.session_state.get("dataset")
41
+
42
+ if df is not None:
43
+ st.subheader("Dataset Preview:")
44
+ st.write(df, use_container_width=True)
45
+
46
+ st.subheader("Info of the Dataset:")
47
+ buffer = StringIO()
48
+ df.info(buf=buffer)
49
+ st.text(buffer.getvalue())
50
+
51
+ st.subheader("Dataset Shape (Rows, Columns):")
52
+ st.write(df.shape)
53
+
54
+ st.markdown('''**Dataset :**
55
+ | **Feature** | **Description** | **Example** |
56
+ |--------------------------|--------------------------------------------------------------------|------------------------------|
57
+ | **gender** | Represents the gender of the individual. | "Female","Male" |
58
+ | **age** | Represents the age of the individual in years.. | 45 |
59
+ | **hypertension** | Indicates whether the individual has hypertension . | 1 |
60
+ | **heart_disease** | Indicates whether the individual has a history of heart disease. | 0 |
61
+ | **ever_married** | Indicates whether the individual has ever been married. | "Yes" |
62
+ | **work_type** | Gender of the customer (0 - Male, 1 - Female). | "Self-employed |
63
+ | **Residence_type** |Indicates whether the individual resides in an urban or rural area. | "Urban" |
64
+ | **avg_glucose_level** | Represents the average glucose level in the blood (in mg/dL).. | 132.5 |
65
+ | **bmi** | Represents the individual's Body Mass Index (BMI), calculated as. | 27.4 |
66
+ | **smoking_status** | Represents the individual's smoking habits | "Never smoked" |
67
+ | **stroke** | Indicates whether the individual has had a stroke. | 0 (No), 1 (Yes) |
68
+ ''')
69
+
70
+
71
+
72
+ else:
73
+ st.info("No dataset found. Please upload a CSV file.")
74
+
75
+ # Define the URL of the background image (use your own image URL)
76
+ background_image_url = "https://cdn-uploads.huggingface.co/production/uploads/67441c51a784a9d15cb12871/xpoN_mbctlrQAgRU06EPt.jpeg"
77
+
78
+ # Apply custom CSS for the background image and overlay
79
+ st.markdown(
80
+ f"""
81
+ <style>
82
+ .stApp {{
83
+ background-image: url("{background_image_url}");
84
+ background-size: cover;
85
+ background-position: center;
86
+ height: 100vh;
87
+ }}
88
+
89
+ /* Semi-transparent overlay */
90
+ .stApp::before {{
91
+ content: "";
92
+ position: absolute;
93
+ top: 0;
94
+ left: 0;
95
+ width: 100%;
96
+ height: 100%;
97
+ background: rgba(0, 0, 0, 0.4);
98
+ z-index: -1;
99
+ }}
100
+
101
+ /* Styling the content to ensure text visibility */
102
+ .stMarkdown {{
103
+ color: white;
104
+ font-size: 100px;
105
+ }}
106
+ </style>
107
+ """,
108
+ unsafe_allow_html=True
109
+ )
110
+
111
+
112
+ if st.button("Previous ⏮️"):
113
+ st.switch_page("pages/0_Problem-Statement_and_Aim.py")
114
+ if st.button("Next ⏭️"):
115
+ st.switch_page("pages/2_Data_CLeaning_and_Preprocessing.py")