Sindhuprakash commited on
Commit
0e3204f
·
verified ·
1 Parent(s): ea5cff3

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ import os
5
+
6
+ # Load the saved model
7
+ model_path = "ADAB_TunedModle.joblib"
8
+ try:
9
+ model = joblib.load('ADAB_TunedModle.joblib')
10
+ st.success("Model loaded successfully.")
11
+ except FileNotFoundError:
12
+ st.error(f"Model file not found at {model_path}. Please check the file path.")
13
+ st.stop()
14
+ except Exception as e:
15
+ st.error(f"Error loading model: {str(e)}")
16
+ st.stop()
17
+
18
+ # Streamlit app title
19
+ st.title("ExtraLearn Customer Status Prediction")
20
+
21
+ # Description
22
+ st.write("Enter customer details to predict their status (0 or 1).")
23
+
24
+ # Input fields for numerical features
25
+ st.header("Numerical Features")
26
+ age = st.number_input("Age", min_value=18, max_value=100, value=30)
27
+ website_visits = st.number_input("Website Visits", min_value=0, value=5)
28
+ time_spent_on_website = st.number_input("Time Spent on Website (seconds)", min_value=0, value=500)
29
+ page_views_per_visit = st.number_input("Page Views per Visit", min_value=0.0, value=2.0)
30
+
31
+ # Input fields for categorical features
32
+ st.header("Categorical Features")
33
+ current_occupation = st.selectbox("Current Occupation", ["Unemployed", "Professional", "Student"])
34
+ first_interaction = st.selectbox("First Interaction", ["Website", "Mobile App"])
35
+ profile_completed = st.selectbox("Profile Completed", ["Low", "Medium", "High"])
36
+ last_activity = st.selectbox("Last Activity", ["Website Activity", "Email Activity", "Phone Activity"])
37
+ print_media_type1 = st.selectbox("Print Media Type 1", ["Yes", "No"])
38
+ print_media_type2 = st.selectbox("Print Media Type 2", ["Yes", "No"])
39
+ digital_media = st.selectbox("Digital Media", ["Yes", "No"])
40
+ educational_channels = st.selectbox("Educational Channels", ["Yes", "No"])
41
+ referral = st.selectbox("Referral", ["Yes", "No"])
42
+
43
+ # Prepare input data for prediction
44
+ input_data = pd.DataFrame({
45
+ "age": [age],
46
+ "website_visits": [website_visits],
47
+ "time_spent_on_website": [time_spent_on_website],
48
+ "page_views_per_visit": [page_views_per_visit],
49
+ "current_occupation": [current_occupation],
50
+ "first_interaction": [first_interaction],
51
+ "profile_completed": [profile_completed],
52
+ "last_activity": [last_activity],
53
+ "print_media_type1": [print_media_type1],
54
+ "print_media_type2": [print_media_type2],
55
+ "digital_media": [digital_media],
56
+ "educational_channels": [educational_channels],
57
+ "referral": [referral]
58
+ })
59
+
60
+ # Predict button
61
+ if st.button("Predict"):
62
+ try:
63
+ prediction = model.predict(input_data)[0]
64
+ # Since this is a regression model, round the prediction for clarity
65
+ status = round(prediction)
66
+ st.success(f"Predicted Status: {status} (Raw prediction value: {prediction:.4f})")
67
+ if status == 1:
68
+ st.write("The customer is likely to be in status 1 (e.g., engaged or converted).")
69
+ else:
70
+ st.write("The customer is likely to be in status 0 (e.g., not engaged or not converted).")
71
+ except Exception as e:
72
+ st.error(f"Error in prediction: {str(e)}")
73
+
74
+ # Display model details
75
+
76
+ st.write("Features used: age, website_visits, time_spent_on_website, page_views_per_visit, current_occupation, first_interaction, profile_completed, last_activity, print_media_type1, print_media_type2, digital_media, educational_channels, referral.")