|
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 |
|
|
|
|
|
st.set_page_config(page_title="π Heartify", layout="centered", page_icon="π") |
|
|
|
|
|
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 |
|
) |
|
|
|
|
|
df = pd.read_csv("data.csv") |
|
|
|
|
|
for col in ["Timestamp", "Email Address"]: |
|
if col in df.columns: |
|
df.drop(columns=col, inplace=True) |
|
|
|
|
|
encoders = {} |
|
for col in df.columns: |
|
le = LabelEncoder() |
|
df[col] = le.fit_transform(df[col]) |
|
encoders[col] = le |
|
|
|
|
|
x = df.iloc[:, :-1] |
|
y = df.iloc[:, -1] |
|
|
|
|
|
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()]) |
|
|
|
|
|
st.title("π Heartify") |
|
st.markdown("#### *Let your heart meet its algorithm*") |
|
st.caption("π¬ ΰ°Ήΰ±ΰ°¦ΰ°―ΰ°Ύΰ°²ΰ°¨ΰ± ΰ°
ΰ°¨ΰ±ΰ°Έΰ°ΰ°§ΰ°Ύΰ°¨ΰ°Ώΰ°ΰ°ΰ± ΰ°ΰ°ΰ±ΰ° AI - Heartify") |
|
st.divider() |
|
|
|
|
|
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!") |
|
|
|
|
|
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] |
|
|
|
|
|
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.") |
|
|