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gradio as gr
|
| 5 |
+
|
| 6 |
+
# Load the pre-trained model
|
| 7 |
+
with open('src/models/crimson_nebula.pkl', 'rb') as f:
|
| 8 |
+
model = pickle.load(f)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
# Define the prediction function
|
| 12 |
+
def predict_crimson_nebula(*inputs):
|
| 13 |
+
input_data = dict(zip(feature_names, inputs))
|
| 14 |
+
input_df = pd.DataFrame([input_data])
|
| 15 |
+
prediction = model.predict(input_df)
|
| 16 |
+
return prediction[0]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Define features name
|
| 20 |
+
feature_names = [
|
| 21 |
+
"age",
|
| 22 |
+
"gender",
|
| 23 |
+
"country",
|
| 24 |
+
"urban_rural",
|
| 25 |
+
"income_level",
|
| 26 |
+
"employment_status",
|
| 27 |
+
"education_level",
|
| 28 |
+
"relationship_status",
|
| 29 |
+
"has_children",
|
| 30 |
+
"exercise_hours_per_week",
|
| 31 |
+
"sleep_hours_per_night",
|
| 32 |
+
"diet_quality",
|
| 33 |
+
"smoking",
|
| 34 |
+
"alcohol_frequency",
|
| 35 |
+
"perceived_stress_score",
|
| 36 |
+
"body_mass_index",
|
| 37 |
+
"blood_pressure_systolic",
|
| 38 |
+
"blood_pressure_diastolic",
|
| 39 |
+
"daily_steps_count",
|
| 40 |
+
"weekly_work_hours",
|
| 41 |
+
"hobbies_count",
|
| 42 |
+
"social_events_per_month",
|
| 43 |
+
"books_read_per_year",
|
| 44 |
+
"volunteer_hours_per_month",
|
| 45 |
+
"travel_frequency_per_year",
|
| 46 |
+
"daily_active_minutes_instagram",
|
| 47 |
+
"sessions_per_day",
|
| 48 |
+
"posts_created_per_week",
|
| 49 |
+
"reels_watched_per_day",
|
| 50 |
+
"stories_viewed_per_day",
|
| 51 |
+
"likes_given_per_day",
|
| 52 |
+
"comments_written_per_day",
|
| 53 |
+
"dms_sent_per_week",
|
| 54 |
+
"dms_received_per_week",
|
| 55 |
+
"ads_viewed_per_day",
|
| 56 |
+
"ads_clicked_per_day",
|
| 57 |
+
"time_on_feed_per_day",
|
| 58 |
+
"time_on_explore_per_day",
|
| 59 |
+
"time_on_messages_per_day",
|
| 60 |
+
"time_on_reels_per_day",
|
| 61 |
+
"followers_count",
|
| 62 |
+
"following_count",
|
| 63 |
+
"uses_premium_features",
|
| 64 |
+
"notification_response_rate",
|
| 65 |
+
"account_creation_year",
|
| 66 |
+
"average_session_length_minutes",
|
| 67 |
+
"content_type_preference",
|
| 68 |
+
"preferred_content_theme",
|
| 69 |
+
"privacy_setting_level",
|
| 70 |
+
"two_factor_auth_enabled",
|
| 71 |
+
"biometric_login_used",
|
| 72 |
+
"linked_accounts_count",
|
| 73 |
+
"subscription_status",
|
| 74 |
+
"user_engagement_score"
|
| 75 |
+
]
|
| 76 |
+
|
| 77 |
+
# Define the input and output components
|
| 78 |
+
input_components = [
|
| 79 |
+
gr.Slider(10, 70, step=1, label="Age"),
|
| 80 |
+
gr.Dropdown(["Male", "Female", "Non-binary", "Prefer not to say"], label="Gender"),
|
| 81 |
+
gr.Dropdown(["United States", "India", "Brazil", "Other", "United Kingdom", "Canada", "Australia", "South Korea", "Germany", "Japan"], label="Country"),
|
| 82 |
+
gr.Dropdown(["Urban", "Suburban", "Rural"], label="Urban/Rural"),
|
| 83 |
+
gr.Dropdown(["Low", "Lower-middle", "Middle", "Upper-middle", "High"], label="Income Level"),
|
| 84 |
+
gr.Dropdown(["Full-time employed", "Student", "Freelancer", "Unemployed", "Part-time", "Retired"], label="Employment Status"),
|
| 85 |
+
gr.Dropdown(["Bachelor's", "High School", "Some College", "Master's", "Other", "PhD"], label="Education Level"),
|
| 86 |
+
gr.Dropdown(["Single", "Married", "In a relationship", "Divorced", "Widowed"], label="Relationship Status"),
|
| 87 |
+
gr.Dropdown(["False", "True"], label="Has Children"),
|
| 88 |
+
gr.Slider(0, 20, step=1, label="Exercise Hours per Week"),
|
| 89 |
+
gr.Slider(0, 12, step=1, label="Sleep Hours per Night"),
|
| 90 |
+
gr.Dropdown(["Average", "Good", "Poor", "Very Poor", "Excellent"], label="Diet Quality"),
|
| 91 |
+
gr.Dropdown(["Yes", "No", "Former"], label="Smoking"),
|
| 92 |
+
gr.Dropdown(["Rarely", "Never", "Weekly", "Several times a week", "Daily"], label="Alcohol Frequency"),
|
| 93 |
+
gr.Slider(0, 40, step=1, label="Perceived Stress Score"),
|
| 94 |
+
gr.Slider(10, 40, step=1, label="Body Mass Index"),
|
| 95 |
+
gr.Slider(90, 180, step=1, label="Blood Pressure Systolic"),
|
| 96 |
+
gr.Slider(60, 120, step=1, label="Blood Pressure Diastolic"),
|
| 97 |
+
gr.Slider(0, 30000, step=100, label="Daily Steps Count"),
|
| 98 |
+
gr.Slider(0, 100, step=1, label="Weekly Work Hours"),
|
| 99 |
+
gr.Slider(0, 20, step=1, label="Hobbies Count"),
|
| 100 |
+
gr.Slider(0, 30, step=1, label="Social Events per Month"),
|
| 101 |
+
gr.Slider(0, 50, step=1, label="Books Read per Year"),
|
| 102 |
+
gr.Slider(0, 100, step=1, label="Volunteer Hours per Month"),
|
| 103 |
+
gr.Slider(0, 20, step=1, label="Travel Frequency per Year"),
|
| 104 |
+
gr.Slider(0, 300, step=10, label="Daily Active Minutes on Instagram"),
|
| 105 |
+
gr.Slider(0, 50, step=1, label="Sessions per Day"),
|
| 106 |
+
gr.Slider(0, 50, step=1, label="Posts Created per Week"),
|
| 107 |
+
gr.Slider(0, 300, step=10, label="Reels Watched per Day"),
|
| 108 |
+
gr.Slider(0, 500, step=10, label="Stories Viewed per Day"),
|
| 109 |
+
gr.Slider(0, 1000, step=10, label="Likes Given per Day"),
|
| 110 |
+
gr.Slider(0, 100, step=1, label="Comments Written per Day"),
|
| 111 |
+
gr.Slider(0, 200, step=1, label="DMs Sent per Week"),
|
| 112 |
+
gr.Slider(0, 200, step=1, label="DMs Received per Week"),
|
| 113 |
+
gr.Slider(0, 500, step=10, label="Ads Viewed per Day"),
|
| 114 |
+
gr.Slider(0, 100, step=1, label="Ads Clicked per Day"),
|
| 115 |
+
gr.Slider(0, 180, step=5, label="Time on Feed per Day (minutes)"),
|
| 116 |
+
gr.Slider(0, 120, step=5, label="Time on Explore per Day (minutes)"),
|
| 117 |
+
gr.Slider(0, 60, step=5, label="Time on Messages per Day (minutes)"),
|
| 118 |
+
gr.Slider(0, 180, step=5, label="Time on Reels per Day (minutes)"),
|
| 119 |
+
gr.Slider(0, 100000, step=1000, label="Followers Count"),
|
| 120 |
+
gr.Slider(0, 5000, step=100, label="Following Count"),
|
| 121 |
+
gr.Dropdown(["False", "True"], label="Uses Premium Features"),
|
| 122 |
+
gr.Slider(0, 100, step=1, label="Notification Response Rate (%)"),
|
| 123 |
+
gr.Slider(2005, 2024, step=1, label="Account Creation Year"),
|
| 124 |
+
gr.Slider(1, 180, step=1, label="Average Session Length (minutes)"),
|
| 125 |
+
gr.Dropdown(["Reels", "Stories", "Live", "Mixed", "Photos"], label="Content Type Preference"),
|
| 126 |
+
gr.Dropdown(["Fashion", "Travel", "Food", "Fitness", "Art", "Music", "Tech", "Other"], label="Preferred Content Theme"),
|
| 127 |
+
gr.Dropdown(["Public", "Private", "Friends only"], label="Privacy Setting Level"),
|
| 128 |
+
gr.Dropdown(["False", "True"], label="Two-Factor Authentication Enabled"),
|
| 129 |
+
gr.Dropdown(["False", "True"], label="Biometric Login Used"),
|
| 130 |
+
gr.Slider(0, 10, step=1, label="Linked Accounts Count"),
|
| 131 |
+
gr.Dropdown(["Free", "Premium", "Business"], label="Subscription Status"),
|
| 132 |
+
gr.Slider(0, 100, step=1, label="User Engagement Score")
|
| 133 |
+
]
|
| 134 |
+
|
| 135 |
+
output_component = gr.Label(label="Crimson Nebula Prediction")
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
# Interface
|
| 139 |
+
app = gr.Interface(
|
| 140 |
+
fn=predict_crimson_nebula,
|
| 141 |
+
inputs=input_components,
|
| 142 |
+
outputs=output_component,
|
| 143 |
+
title="Crimson Nebula",
|
| 144 |
+
description="Happiness Prediction Model"
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
# Launch the app
|
| 149 |
+
if __name__ == "__main__":
|
| 150 |
+
app.launch()
|