import gradio as gr import joblib import numpy as np import os import pandas as pd # Load model and scaler model_path = os.path.join(os.path.dirname(__file__), "dating_model.joblib") scaler_path = os.path.join(os.path.dirname(__file__), "dating_scaler.joblib") model = joblib.load(model_path) scaler = joblib.load(scaler_path) def predict( hobbies_matched, is_job_matched, is_edu_matched, is_religion_match, is_interested_in_match, profile_completion, no_of_photos, miles_away, age ): """ Make prediction with the model """ # Convert inputs to appropriate format features = np.array([[ hobbies_matched, int(is_job_matched), int(is_edu_matched), int(is_religion_match), int(is_interested_in_match), profile_completion, no_of_photos, miles_away, age ]]) # Scale the features scaled_features = scaler.transform(features) # Make prediction prediction = model.predict(scaled_features)[0] if prediction == 1: return "Swipe Right (Like)" else: return "Swipe Left (Pass)" # Create the interface with gr.Blocks(title="Dating App Swipe Predictor") as demo: gr.Markdown("# Dating App Swipe Predictor") gr.Markdown("Enter profile information to predict whether a user will swipe right (like) or left (pass).") with gr.Row(): with gr.Column(): hobbies_matched = gr.Slider(minimum=0, maximum=10, step=1, label="Number of Matched Hobbies") is_job_matched = gr.Checkbox(label="Jobs Match?") is_edu_matched = gr.Checkbox(label="Education Level Matches?") is_religion_match = gr.Checkbox(label="Religion Matches?") is_interested_in_match = gr.Checkbox(label="Interests Match?") profile_completion = gr.Slider(minimum=0, maximum=100, step=1, label="Profile Completion %") no_of_photos = gr.Slider(minimum=0, maximum=10, step=1, label="Number of Photos") miles_away = gr.Slider(minimum=0, maximum=100, step=1, label="Miles Away") age = gr.Slider(minimum=18, maximum=80, step=1, label="Age") predict_btn = gr.Button("Predict Swipe") with gr.Column(): output = gr.Textbox(label="Prediction Result") predict_btn.click( fn=predict, inputs=[ hobbies_matched, is_job_matched, is_edu_matched, is_religion_match, is_interested_in_match, profile_completion, no_of_photos, miles_away, age ], outputs=output ) gr.Markdown(""" ## About This Model This model predicts whether a user will swipe right (like) or left (pass) on a dating app profile based on various features. The model was trained on historical swiping data and uses logistic regression with mini-batch gradient descent. ### Features Used: - Number of matched hobbies - Job match status - Education match status - Religion match status - Interest match status - Profile completion percentage - Number of profile photos - Distance (in miles) - Age ### Model Performance: - Accuracy: 85.2% - Precision: 83.7% - Recall: 79.1% Note: The model provides predictions based on patterns in historical data but individual preferences may vary. """) # Launch the app if __name__ == "__main__": demo.launch(share=True)