Spaces:
Runtime error
Runtime error
File size: 4,090 Bytes
4d39fa0 |
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
import streamlit as st
import requests
# -----------------------------
# Page Configuration
# -----------------------------
st.set_page_config(
page_title="ExtraaLearn | Lead Conversion Predictor",
page_icon="π",
layout="centered"
)
# -----------------------------
# App Header
# -----------------------------
st.title("π ExtraaLearn Lead Conversion Prediction")
st.markdown(
"""
This application predicts whether a **lead is likely to convert**
into a **paid customer** based on their interaction and engagement data.
"""
)
st.divider()
# -----------------------------
# Lead Details Input
# -----------------------------
st.subheader("π Lead Information")
lead_id = st.text_input("Lead ID")
age = st.number_input("Age", min_value=18, max_value=70, value=30)
current_occupation = st.selectbox(
"Current Occupation",
["Professional", "Unemployed", "Student"]
)
first_interaction = st.selectbox(
"First Interaction Channel",
["Website", "Mobile App"]
)
profile_completed = st.selectbox(
"Profile Completion Level",
["Low", "Medium", "High"]
)
website_visits = st.number_input(
"Number of Website Visits",
min_value=0,
value=5
)
time_spent_on_website = st.number_input(
"Total Time Spent on Website (seconds)",
min_value=0,
value=600
)
page_views_per_visit = st.number_input(
"Average Page Views per Visit",
min_value=0.0,
value=3.0
)
last_activity = st.selectbox(
"Last Activity Type",
["Email Activity", "Phone Activity", "Website Activity"]
)
st.subheader("π£ Marketing Touchpoints")
print_media_type1 = st.selectbox(
"Seen Newspaper Advertisement?",
["No", "Yes"]
)
print_media_type2 = st.selectbox(
"Seen Magazine Advertisement?",
["No", "Yes"]
)
digital_media = st.selectbox(
"Seen Digital Advertisement?",
["No", "Yes"]
)
educational_channels = st.selectbox(
"Heard via Educational Channels?",
["No", "Yes"]
)
referral = st.selectbox(
"Heard via Referral?",
["No", "Yes"]
)
# -----------------------------
# Prepare Payload
# -----------------------------
payload = {
"ID": lead_id,
"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": 1 if print_media_type1 == "Yes" else 0,
"print_media_type2": 1 if print_media_type2 == "Yes" else 0,
"digital_media": 1 if digital_media == "Yes" else 0,
"educational_channels": 1 if educational_channels == "Yes" else 0,
"referral": 1 if referral == "Yes" else 0
}
# -----------------------------
# Prediction Button
# -----------------------------
if st.button("π Predict Lead Conversion", type="primary"):
try:
response = requests.post(
"https://ankitasml-extraalearn.hf.space/v1/predict",
json=payload,
timeout=10
)
if response.status_code == 200:
result = response.json()
prediction = result["prediction"]
probability = result["probability"]
st.divider()
st.subheader("π Prediction Result")
if prediction == 1:
st.success(
f"β
**Lead is likely to convert**\n\n"
f"π Conversion Probability: **{probability*100:.2f}%**"
)
else:
st.warning(
f"β οΈ **Lead is unlikely to convert**\n\n"
f"π Conversion Probability: **{probability*100:.2f}%**"
)
else:
st.error("β API Error: Unable to fetch prediction.")
except Exception as e:
st.error(f"π¨ Connection Error: {e}")
# -----------------------------
# Footer
# -----------------------------
st.divider()
st.caption("π Internal Use | ExtraaLearn Lead Analytics")
|