Spaces:
Sleeping
Sleeping
File size: 3,351 Bytes
2639209 7bf2bfa 7607c02 7bf2bfa 2639209 7607c02 7bf2bfa 7607c02 7bf2bfa 7607c02 2639209 7bf2bfa 2639209 7bf2bfa 2639209 7bf2bfa 2639209 7bf2bfa 2639209 7bf2bfa 2639209 7607c02 2639209 7607c02 7bf2bfa 2639209 7bf2bfa 2639209 7607c02 7bf2bfa 7607c02 7bf2bfa 2639209 7607c02 2639209 7607c02 2639209 7607c02 2639209 |
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 |
import streamlit as st
import requests
st.set_page_config(
page_title="ExtraaLearn Lead Conversion Predictor",
layout="centered"
)
st.title("๐ ExtraaLearn Lead Conversion Prediction")
st.write("Fill in the lead details below to predict conversion likelihood.")
# ---------------- INPUT FIELDS ---------------- #
age = st.number_input("Age", min_value=18, max_value=80, value=57)
current_occupation = st.selectbox(
"Current Occupation",
["Student", "Working Professional", "Unemployed"]
)
first_interaction = st.selectbox(
"First Interaction",
["Website", "Email", "Referral", "Social Media"]
)
profile_completed = st.selectbox(
"Profile Completion Level",
["Low", "Medium", "High"]
)
website_visits = st.number_input(
"Website Visits", min_value=0, max_value=100, value=7
)
time_spent_on_website = st.number_input(
"Time Spent on Website (seconds)", min_value=0, value=1639
)
page_views_per_visit = st.number_input(
"Page Views per Visit", min_value=0.0, value=1.861
)
last_activity = st.selectbox(
"Last Activity",
["Website Activity", "Email Opened", "SMS Clicked", "Form Submitted"]
)
print_media_type1 = st.selectbox(
"Print Media Type 1",
["Yes", "No"]
)
print_media_type2 = st.selectbox(
"Print Media Type 2",
["Yes", "No"]
)
digital_media = st.selectbox(
"Digital Media",
["Yes", "No"]
)
educational_channels = st.selectbox(
"Educational Channels",
["Yes", "No"]
)
referral = st.selectbox(
"Referral",
["Yes", "No"]
)
# ---------------- PREDICT ---------------- #
if st.button("Predict Conversion"):
payload = {
"inputs": [
{
"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
}
]
}
BACKEND_URL = "https://rohitmv-extra-learn-be.hf.space/predict"
try:
response = requests.post(BACKEND_URL, json=payload, timeout=15)
if response.status_code == 200:
result = response.json()
st.success("Prediction Successful")
st.metric(
"Conversion Probability",
f"{int(result['conversion_probability'] * 100)}%"
)
st.write(
"### โ
Likely to Convert"
if result["prediction"] == 1
else "### โ Unlikely to Convert"
)
st.write(f"**Lead Category:** {result['lead_category']}")
else:
st.error("Backend error")
st.json(response.json())
except Exception as e:
st.error("Could not connect to backend")
st.write(str(e))
|