Spaces:
Sleeping
Sleeping
Download app.py from Boorla/Match_Prediction: direct link, hf CLI and curl.
- Browser
- Download file 2.71 kB
-
https://huggingface.co/spaces/Boorla/Match_Prediction/resolve/main/app.py
- Command line
-
hf download hf://spaces/Boorla/Match_Prediction/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Boorla/Match_Prediction/resolve/main/app.py
2.71 kB
| 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 | |
| # Load dataset directly from file path | |
| df = pd.read_csv(r"Assessment - Form Responses.csv") | |
| # Streamlit config | |
| st.set_page_config(page_title=" Match Prediction Using Personality and Lifestyle Data", layout="centered") | |
| st.title("Match Prediction Using Personality and Lifestyle Data") | |
| # Drop unwanted columns | |
| if "Timestamp" in df.columns and "Email Address" in df.columns: | |
| df.drop(columns=["Timestamp", "Email Address"], inplace=True) | |
| # Show data | |
| st.subheader("๐ Raw Data") | |
| st.write(df.head()) | |
| # Save original for UI | |
| original_df = df.copy() | |
| # Label Encoding | |
| encoders = {} | |
| for col in df.columns: | |
| le = LabelEncoder() | |
| df[col] = le.fit_transform(df[col]) | |
| encoders[col] = le | |
| # Features and labels (last column = label) | |
| x = df.iloc[:, :-1] | |
| y = df.iloc[:, -1] | |
| # Build ANN | |
| 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()]) | |
| # Train model | |
| if st.button("๐ Train Model"): | |
| checkpoint_cb = keras.callbacks.ModelCheckpoint( | |
| "best_model.h5", monitor="val_loss", save_best_only=True, mode="min" | |
| ) | |
| with st.spinner("Training in progress..."): | |
| history = model.fit(x, y, validation_split=0.2, batch_size=8, epochs=30, | |
| callbacks=[checkpoint_cb], verbose=0) | |
| st.success("โ Model training completed!") | |
| # Prediction section | |
| st.subheader("๐ก Make a Prediction") | |
| user_inputs = {} | |
| for col in x.columns: | |
| options = encoders[col].classes_ | |
| selected = st.selectbox(f"Select {col}:", options) | |
| user_inputs[col] = encoders[col].transform([selected])[0] | |
| if st.button("๐ฎ Predict Match"): | |
| input_df = pd.DataFrame([user_inputs.values()], columns=user_inputs.keys()) | |
| prediction = model.predict(input_df)[0][0] | |
| if prediction >= 0.5: | |
| st.success(f"๐ It's a Match! (Confidence: {round(prediction * 100, 2)}%)") | |
| else: | |
| st.warning(f"๐ No Match. (Confidence: {round((1 - prediction) * 100, 2)}%)") | |