YAMITEK commited on
Commit
b6345bc
·
verified ·
1 Parent(s): 352c5ba

Upload 7 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ life_expectancy_document.pdf filter=lfs diff=lfs merge=lfs -text
Life%20Expectancy%20Data.csv ADDED
The diff for this file is too large to render. See raw diff
 
app (1).py ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import torch
4
+ import torch.nn as nn
5
+ from sklearn.preprocessing import StandardScaler, LabelEncoder
6
+
7
+ st.set_page_config(layout="wide")
8
+
9
+ # Add custom CSS for background image and styling
10
+ # Add custom CSS for background image and styling
11
+ st.markdown("""
12
+ <style>
13
+ .stApp {
14
+ background-image: url("https://cdn.pixabay.com/photo/2020/01/28/11/14/galaxy-4799471_1280.jpg");
15
+ background-size: cover;
16
+ background-position: center;
17
+ background-repeat: no-repeat;
18
+ height: auto; /* Allows the page to expand for scrolling */
19
+ overflow: auto; /* Enables scrolling if the page content overflows */
20
+ }
21
+
22
+ /* Adjust opacity of overlay to make content more visible */
23
+ .stApp::before {
24
+ content: "";
25
+ position: absolute;
26
+ top: 0;
27
+ left: 0;
28
+ width: 100%;
29
+ height: 100%;
30
+ background-color: rgba(255, 255, 255, 0); /* Slightly higher opacity */
31
+ z-index: 0;
32
+ }
33
+
34
+ /* Ensure content appears above the overlay */
35
+ .stApp > * {
36
+ position: relative;
37
+ z-index: 1;
38
+ }
39
+
40
+ /* Ensure the dataframe is visible */
41
+ .dataframe {
42
+ background-color: rgba(255, 255, 255, 0.9) !important;
43
+ z-index: 2;
44
+ }
45
+
46
+ /* Style text elements for better visibility */
47
+ h1, h3, span, div {
48
+ text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.2);
49
+ }
50
+ </style>
51
+ """, unsafe_allow_html=True)
52
+
53
+
54
+ # Custom title styling functions
55
+ def colored_title(text, color):
56
+ st.markdown(f"<h1 style='color: {color};'>{text}</h1>", unsafe_allow_html=True)
57
+
58
+ def colored_subheader(text, color):
59
+ st.markdown(f"<h3 style='color: {color};'>{text}</h3>", unsafe_allow_html=True)
60
+
61
+ def colored_text(text, color):
62
+ st.markdown(f"<span style='color: {color};'>{text}</span>", unsafe_allow_html=True)
63
+
64
+ class ANNModel(nn.Module):
65
+ def __init__(self, input_size):
66
+ super(ANNModel, self).__init__()
67
+ self.fc1 = nn.Linear(input_size, 64)
68
+ self.fc2 = nn.Linear(64, 32)
69
+ self.fc3 = nn.Linear(32, 1)
70
+
71
+ def forward(self, x):
72
+ x = torch.relu(self.fc1(x))
73
+ x = torch.relu(self.fc2(x))
74
+ x = self.fc3(x)
75
+ return x
76
+
77
+ @st.cache_resource
78
+ def load_model():
79
+ _, X_scaled, _ = load_and_preprocess_data()
80
+ input_size = X_scaled.shape[1]
81
+
82
+ model = ANNModel(input_size=input_size)
83
+ try:
84
+ state_dict = torch.load('model_weights.pth', map_location=torch.device('cpu'))
85
+ model.load_state_dict(state_dict)
86
+ model.eval()
87
+ return model
88
+ except Exception as e:
89
+ st.error(f"Error loading model: {str(e)}")
90
+ return None
91
+
92
+ @st.cache_data
93
+ def load_and_preprocess_data():
94
+ df = pd.read_csv('Life Expectancy Data.csv')
95
+ df.columns = df.columns.str.strip()
96
+
97
+ df_display = df.copy()
98
+
99
+ expected_features = [
100
+ 'Adult Mortality', 'infant deaths', 'Alcohol', 'percentage expenditure', 'Hepatitis B',
101
+ 'Measles', 'BMI', 'under-five deaths', 'Polio', 'Total expenditure',
102
+ 'Diphtheria', 'HIV/AIDS', 'GDP', 'Population', 'thinness 1-19 years',
103
+ 'thinness 5-9 years', 'Income composition of resources', 'Schooling',
104
+ 'Country', 'Status', 'Year'
105
+ ]
106
+
107
+ for feature in expected_features:
108
+ if feature not in df.columns:
109
+ st.warning(f"Missing column '{feature}' - Creating with default values")
110
+ df[feature] = 0
111
+ df_display[feature] = 0
112
+
113
+ for column in df.columns:
114
+ if df[column].dtype == 'object':
115
+ fill_value = df[column].mode()[0]
116
+ df[column].fillna(fill_value, inplace=True)
117
+ df_display[column].fillna(fill_value, inplace=True)
118
+ else:
119
+ fill_value = df[column].median()
120
+ df[column].fillna(fill_value, inplace=True)
121
+ df_display[column].fillna(fill_value, inplace=True)
122
+
123
+ label_encoders = {}
124
+ categorical_cols = ['Country', 'Status']
125
+ for col in categorical_cols:
126
+ le = LabelEncoder()
127
+ df[col] = le.fit_transform(df[col].astype(str))
128
+ label_encoders[col] = le
129
+
130
+ X = df[expected_features]
131
+ y = df['Life expectancy']
132
+
133
+ scaler = StandardScaler()
134
+ X_scaled = scaler.fit_transform(X)
135
+
136
+ return df_display, X_scaled, y
137
+
138
+ def main():
139
+ colored_title("Life Expectancy Estimation", "yellow")
140
+
141
+ df_display, X_scaled, y = load_and_preprocess_data()
142
+
143
+ colored_subheader("Dataset Preview", "yellow")
144
+ st.dataframe(df_display.head())
145
+
146
+ colored_subheader("Select a Row for Prediction:", "yellow")
147
+ colored_text("Select a Row Index", "red")
148
+ selected_row_index = st.selectbox("", options=range(len(df_display)), index=0, label_visibility="collapsed")
149
+
150
+ predict_button = st.button("Predict Life Expectancy")
151
+
152
+ if predict_button:
153
+ model = load_model()
154
+ if model is not None:
155
+ row_to_predict = X_scaled[selected_row_index].reshape(1, -1)
156
+ row_tensor = torch.tensor(row_to_predict, dtype=torch.float32)
157
+
158
+ try:
159
+ with torch.no_grad():
160
+ prediction = model(row_tensor).item()
161
+ colored_subheader("Prediction Results:", "yellow")
162
+ colored_text(f"Predicted Life Expectancy: {prediction:.2f} years", "red")
163
+ except RuntimeError as e:
164
+ st.error(f"Prediction error: {str(e)}")
165
+ st.write("Input shape:", row_tensor.shape)
166
+ st.write("Expected shape: 1x21")
167
+
168
+ # Display the selected row with original categorical values
169
+ colored_subheader("Selected Row for Prediction:", "yellow")
170
+ st.write(df_display.iloc[selected_row_index])
171
+
172
+ if __name__ == "__main__":
173
+ main()
background.jpg ADDED
life_expectancy_document.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f7014b03b0a44d3dea99bb76e69b54cee285aab9c65db2c5cb462252f44a0646
3
+ size 200352
life_expectency_notebook.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
model_weights.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee39a9e872a8063898ec8ebc23b1641a504754cc4d0c1ec7896c95b4c7ddc7f3
3
+ size 16708
requirements (1).txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit==1.25.0
2
+ pandas==1.5.3
3
+ numpy==1.24.3
4
+ scikit-learn==1.2.2
5
+ torch==2.0.1
6
+ torchvision==0.15.2
7
+ torchaudio==2.0.2