Spaces:
Runtime error
Runtime error
File size: 2,939 Bytes
d15fe1e 8a6c9f4 d15fe1e 2888847 8a6c9f4 6b866cb 8a6c9f4 6b866cb 8a6c9f4 99c6153 8a6c9f4 d15fe1e 99c6153 d15fe1e 8a6c9f4 d15fe1e 99c6153 d15fe1e 8a6c9f4 d15fe1e 8a6c9f4 d15fe1e 99c6153 d15fe1e 8a6c9f4 | 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 |
# Streamlit Web App for Extraa_Learn prediction
import streamlit as st
import requests
import numpy as np
# App Title
st.title("Extraa Learn Lead Conversion Prediction")
# User Inputs
Age = st.number_input("Age", min_value=18, max_value=100, value=35)
current_occupation = st.selectbox("Current Occupation", ["Professional", "Unemployed", "Student"])
first_interaction = st.selectbox("First Interaction", ["Website", "Mobile App"])
profile_completed = st.selectbox("Profile Completed", ["High", "Medium", "Low"])
website_visits = st.number_input("Website Visits", min_value=0, 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"])
print_media_type1 = st.selectbox("Seen Ad in Newspaper?", ["Yes", "No"])
print_media_type2 = st.selectbox("Seen Ad in Magazine?", ["Yes", "No"])
digital_media = st.selectbox("Seen Ad on Digital Platforms?", ["Yes", "No"])
educational_channels = st.selectbox("Heard via Educational Channels?", ["Yes", "No"])
referral = st.selectbox("Heard via Referral?", ["Yes", "No"])
# Prepare JSON payload for the backend
product_data = {
"age": int(Age),
"current_occupation": current_occupation.strip(),
"first_interaction": first_interaction.strip(),
"profile_completed": profile_completed.strip(),
"website_visits": int(website_visits),
"time_spent_on_website": float(time_spent_on_website),
"page_views_per_visit": float(page_views_per_visit),
"last_activity": last_activity.strip(),
"print_media_type1": print_media_type1,
"print_media_type2": print_media_type2,
"digital_media": digital_media,
"educational_channels": educational_channels,
"referral": referral
}
# Trigger Prediction API Call
if st.button("Predict Status", type='primary'):
try:
# This is level 1 indentation (4 spaces)
response = requests.post(
"https://HSSHETTY01-Extraa_Learn-backend2.hf.space/v1/Status",
json=product_data
)
# This must stay at level 1 indentation (4 spaces)
if response.status_code == 200:
# This is level 2 indentation (8 spaces)
result = response.json()
status_pred = result.get("Status", result.get("prediction", 0))
if status_pred == 1:
st.success("📈 **Status:** Lead is likely to convert!")
else:
st.warning("📉 **Status:** Lead is not likely to convert.")
else:
st.error(f"❌ API Error {response.status_code}: {response.text}")
except Exception as e:
# Aligns perfectly with the 'try:' statement
st.error(f"⚠️ Connection error: {e}")
|