File size: 926 Bytes
7ab5825
 
 
825ab88
7ab5825
825ab88
7ab5825
 
 
 
 
 
 
 
 
 
 
 
 
 
 
825ab88
7ab5825
 
 
 
 
825ab88
 
7ab5825
825ab88
 
 
7ab5825
 
825ab88
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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]