Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import requests | |
| # Set the title and header of the app | |
| st.set_page_config(page_title="ExtraaLearn Lead Conversion Predictor", layout="wide") | |
| st.title("π ExtraaLearn Lead Conversion Predictor") | |
| st.markdown("### Predict whether a lead will convert to a paid customer.") | |
| # --- API Configuration --- | |
| API_URL = "https://Pratik26Dec-ExtraaLearn.hf.space/predict" | |
| # --- User Input Form --- | |
| st.header("Lead Information") | |
| with st.form("lead_form"): | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| age = st.slider("Age", 18, 65, 30) | |
| current_occupation = st.radio("Current Occupation", ['Professional', 'Unemployed', 'Student']) | |
| first_interaction = st.radio("First Interaction", ['Website', 'Mobile App']) | |
| with col2: | |
| profile_completed = st.selectbox("Profile Completed", ['Low', 'Medium', 'High']) | |
| website_visits = st.slider("Website Visits", 0, 30, 3) | |
| time_spent_on_website = st.slider("Time Spent on Website (seconds)", 0, 2600, 500) | |
| with col3: | |
| page_views_per_visit = st.number_input("Pages Viewed per Visit", 0.0, 20.0, 3.0) | |
| last_activity = st.selectbox("Last Activity", ['Email Activity', 'Phone Activity', 'Website Activity']) | |
| st.markdown("<br>", unsafe_allow_html=True) | |
| st.write("---") | |
| st.subheader("Source of Information") | |
| print_media_type1 = st.checkbox("Seen on Newspaper Ad?") | |
| print_media_type2 = st.checkbox("Seen on Magazine Ad?") | |
| digital_media = st.checkbox("Seen on Digital Ad?") | |
| educational_channels = st.checkbox("Heard on Educational Channels?") | |
| referral = st.checkbox("Referred by someone?") | |
| # Submit button for the form | |
| submit_button = st.form_submit_button(label='Predict Lead Conversion') | |
| # --- Prediction Logic --- | |
| if submit_button: | |
| # Prepare data to be sent to the API | |
| input_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": "Yes" if print_media_type1 else "No", | |
| "print_media_type2": "Yes" if print_media_type2 else "No", | |
| "digital_media": "Yes" if digital_media else "No", | |
| "educational_channels": "Yes" if educational_channels else "No", | |
| "referral": "Yes" if referral else "No" | |
| } | |
| with st.spinner("Analyzing lead data..."): | |
| try: | |
| response = requests.post(API_URL, json=input_data) | |
| if response.status_code == 200: | |
| prediction = response.json() | |
| st.success("β Prediction Successful!") | |
| # Display the prediction result | |
| st.write(f"The model predicts this lead is **{prediction['prediction_label']}**.") | |
| st.progress(int(prediction['probabilities']['Converted'] * 100), text="Conversion Probability") | |
| st.info(f"Probability of Conversion: **{prediction['probabilities']['Converted']:.2f}**") | |
| else: | |
| st.error(f"β API call failed with status code: {response.status_code}") | |
| st.json(response.json()) | |
| except requests.exceptions.RequestException as e: | |
| st.error(f"β An error occurred while connecting to the API: {e}") |