File size: 3,361 Bytes
9c8cffd f05e947 9c8cffd f05e947 9c8cffd f05e947 0c44c11 f05e947 ee34b7f 9c8cffd f05e947 9c8cffd f05e947 9c8cffd f05e947 9c8cffd f05e947 9c8cffd f05e947 9c8cffd f05e947 9c8cffd f05e947 9c8cffd f05e947 9c8cffd f05e947 9c8cffd f05e947 9c8cffd f05e947 9c8cffd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
import streamlit as st
import pandas as pd
from sklearn.preprocessing import LabelEncoder
import tensorflow as tf
from tensorflow import keras
from keras.metrics import Precision, Recall
import numpy as np
# β
Set page config β must be the very first Streamlit call
st.set_page_config(page_title="π Heartify", layout="centered", page_icon="π")
# β
CSS Overrides to remove blur/spinner effects
st.markdown(
"""
<style>
[data-testid="stAppViewContainer"] * {
filter: none !important;
-webkit-filter: none !important;
}
div[data-testid="stSpinner"]::before {
background: none !important;
}
[data-baseweb="checkbox"] * {
filter: none !important;
-webkit-filter: none !important;
opacity: 1 !important;
}
[data-baseweb="input"] * {
filter: none !important;
-webkit-filter: none !important;
opacity: 1 !important;
}
.block-container:has(div[aria-busy="true"]) {
pointer-events: auto !important;
}
</style>
""",
unsafe_allow_html=True
)
# β
Load dataset
df = pd.read_csv("data.csv")
# β
Drop unnecessary columns
for col in ["Timestamp", "Email Address"]:
if col in df.columns:
df.drop(columns=col, inplace=True)
# β
Label Encoding
encoders = {}
for col in df.columns:
le = LabelEncoder()
df[col] = le.fit_transform(df[col])
encoders[col] = le
# β
Features and labels
x = df.iloc[:, :-1]
y = df.iloc[:, -1]
# β
Build ANN model
model = keras.Sequential([
keras.layers.Input(shape=(x.shape[1],)),
keras.layers.Dense(8, kernel_initializer=keras.initializers.GlorotNormal(seed=42)),
keras.layers.PReLU(),
keras.layers.Dense(3, kernel_initializer=keras.initializers.GlorotNormal(seed=42),
kernel_regularizer=keras.regularizers.L2()),
keras.layers.PReLU(),
keras.layers.BatchNormalization(),
keras.layers.Dropout(0.2),
keras.layers.Dense(1, activation="sigmoid", kernel_initializer=keras.initializers.HeNormal(seed=42))
])
model.compile(loss="binary_crossentropy", optimizer="adam", metrics=["accuracy", Precision(), Recall()])
# β
App Header
st.title("π Heartify")
st.markdown("#### *Let your heart meet its algorithm*")
st.caption("π¬ ΰ°Ήΰ±ΰ°¦ΰ°―ΰ°Ύΰ°²ΰ°¨ΰ± ΰ°
ΰ°¨ΰ±ΰ°Έΰ°ΰ°§ΰ°Ύΰ°¨ΰ°Ώΰ°ΰ°ΰ± ΰ°ΰ°ΰ±ΰ° AI - Heartify")
st.divider()
# β
Train model on button click
if st.button("β¨ Prepare the Heartify AI"):
with st.spinner("π Training the model... please wait."):
model.fit(x, y, validation_split=0.2, batch_size=8, epochs=30, verbose=0)
st.success("β
Heartify is ready to make predictions!")
# β
User Input
st.subheader("π Tell Us About Yourself")
user_inputs = {}
for col in x.columns:
options = encoders[col].classes_
selected = st.selectbox(f"πΉ {col.replace('_', ' ').title()}", options)
user_inputs[col] = encoders[col].transform([selected])[0]
# β
Predict Compatibility
if st.button("π Check Compatibility"):
input_df = pd.DataFrame([user_inputs.values()], columns=user_inputs.keys())
prediction = model.predict(input_df)[0][0]
st.markdown("---")
if prediction >= 0.5:
st.success("π It's a Match! Your vibes align perfectly π")
else:
st.warning("ποΈ Not quite yet β love takes time. Keep believing.")
|