File size: 2,961 Bytes
e1949a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

import streamlit as st
import requests

# Set page title and icon
st.set_page_config(page_title="ExtraaLearn Lead Prediction", page_icon="🎓")

st.title("🎓 ExtraaLearn: Lead Conversion Prediction")
st.markdown("Enter lead details below to predict the likelihood of conversion.")

# Layout with columns for better UI
col1, col2 = st.columns(2)

with col1:
    age = st.number_input("Age", min_value=18, max_value=65, value=25)
    current_occupation = st.selectbox("Current Occupation", ["Student", "Professional", "Unemployed", "Others"])
    first_interaction = st.selectbox("First Interaction", ["Website", "Mobile App"])
    profile_completed = st.slider("Profile Completed (%)", 0, 100, 50)
    website_visits = st.number_input("Website Visits", min_value=0, value=5)
    referral = st.selectbox("Referral", ["No", "Yes"])

with col2:
    time_spent_on_website = st.number_input("Time Spent on Website (m)", min_value=0, value=300)
    page_views_per_visit = st.number_input("Page Views Per Visit", min_value=0.0, value=2.5)
    last_activity = st.selectbox("Last Activity", ["Email Opened", "Website Activity", "Mobile App Activity", "Others"])
    print_media_type1 = st.selectbox("Print Media (Type 1)", ["No", "Yes"])
    print_media_type2 = st.selectbox("Print Media (Type 2)", ["No", "Yes"])
    digital_media = st.selectbox("Digital Media", ["No", "Yes"])
    educational_channels = st.selectbox("Educational Channels", ["No", "Yes"])

# Prepare the data dictionary for the API
lead_data = {
    "age": age,
    "current_occupation": current_occupation,
    "first_interaction": first_interaction,
    "profile_completed": profile_completed,
    "website_visits": website_visits,
    "time_spent_on_website": time_spent_on_website,
    "page_views_per_visit": page_views_per_visit,
    "last_activity": last_activity,
    "print_media_type1": print_media_type1,
    "print_media_type2": print_media_type2,
    "digital_media": digital_media,
    "educational_channels": educational_channels,
    "referral": referral
}

st.divider()

if st.button("Predict Conversion Potential", type='primary'):
    try:
        # Update the URL below once your backend API is deployed
        api_url = "https://shantanuchande-extlearn-api.hf.space/v1/predict"
        response = requests.post(api_url, json=lead_data)

        if response.status_code == 200:
            result = response.json()
            prediction = result["Status_Prediction"]
            probability = result["Conversion_Probability"]

            if prediction == 1:
                st.success(f"### High Potential Lead!!!!")
                st.write(f"Confidence: {probability*100:.2f}%")
            else:
                st.warning(f"### Low Potential Lead")
                st.write(f"Confidence: {(1-probability)*100:.2f}%")
        else:
            st.error(f"Error in API request: {response.status_code}")
    except Exception as e:
        st.error(f"Connection Error: {e}")