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))