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( """ """, 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.")