import streamlit as st import requests import pandas as pd st.set_page_config(page_title="ExtraaLearn Predictor", layout="centered") st.title("ExtraaLearn Lead Conversion Predictor") # Input fields based on ExtraaLearn dataset features age = st.number_input("Age", min_value=18, max_value=100, value=45) current_occupation = st.selectbox("Current Occupation", ["Professional", "Unemployed", "Student"]) first_interaction = st.selectbox("First Interaction", ["Website", "Mobile App"]) profile_completed = st.selectbox("Profile Completed", ["Low", "Medium", "High"], index=2) # Default High website_visits = st.number_input("Website Visits", min_value=0, max_value=50, value=3) time_spent_on_website = st.number_input("Time Spent on Website (seconds)", min_value=0, value=500) page_views_per_visit = st.number_input("Page Views Per Visit", min_value=0.0, value=3.0) last_activity = st.selectbox("Last Activity", ["Email Activity", "Phone Activity", "Website Activity"]) # Marketing Channels print_media_type1 = st.selectbox("Saw Ad in Newspaper?", ["Yes", "No"], index=1) print_media_type2 = st.selectbox("Saw Ad in Magazine?", ["Yes", "No"], index=1) digital_media = st.selectbox("Saw Ad on Digital Platforms?", ["Yes", "No"], index=1) educational_channels = st.selectbox("Heard via Educational Channels?", ["Yes", "No"], index=1) referral = st.selectbox("Heard via Referral?", ["Yes", "No"], index=1) 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 } if st.button("Predict Propensity", type='primary'): api_url = "https://sirisha335-extraalearn-api.hf.space/v1/predict" with st.spinner("Connecting to API (this may take 20s if the backend is waking up)..."): try: # Increased timeout to 20 seconds to allow for cold starts response = requests.post(api_url, json=lead_data, timeout=20) if response.status_code == 200: result = response.json() prediction = result.get("Conversion_Probability", 0) st.metric("Conversion Propensity", f"{prediction:.4f}") if prediction > 0.5: st.success("This lead is highly likely to convert!") else: st.warning("This lead has a low probability of conversion.") else: st.error(f"API Error: {response.status_code} - {response.text}") except requests.exceptions.Timeout: st.error("The request timed out. The backend Space is likely still starting up or under heavy load. Please try again in a minute.") except Exception as e: st.error(f"Could not connect to the backend. Ensure the Backend Space is 'Running'. Error: {e}")