import joblib import pandas as pd # Load the model and columns model = joblib.load("time_slot_model.joblib") columns = joblib.load("columns.joblib") def preprocess_time(time_str): hour = int(time_str.split(':')[0]) if 'PM' in time_str and hour != 12: hour += 12 if 'AM' in time_str and hour == 12: hour = 0 return hour def categorize_time(hour): if 10 <= hour < 12: return 'morning' elif 12 <= hour < 14: return 'early_noon' elif 14 <= hour < 16: return 'noon' elif 16 <= hour < 17: return 'dusk' else: return 'other' def predict(user_name, user_input): # Process the user input user_input = pd.get_dummies(pd.Series([user_input]), prefix='Pref') user_input = user_input.reindex(columns=columns, fill_value=0) # Predict the preferred time slot prediction = model.predict(user_input) return prediction[0]