Spaces:
Runtime error
Runtime error
| 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") | |