File size: 2,198 Bytes
a9e9f21
2603cfa
a9e9f21
2603cfa
a9e9f21
2603cfa
e1da973
 
 
2603cfa
e1da973
 
a9e9f21
 
 
 
 
2603cfa
a9e9f21
 
 
 
2603cfa
a9e9f21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1da973
a9e9f21
 
 
 
 
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
import os
# Redirect HOME so Streamlit writes under /tmp
os.environ["HOME"] = "/tmp"
# Disable usage stats
os.environ["STREAMLIT_GATHER_USAGE_STATS"] = "false"
# Use tmp for config/cache
os.environ["STREAMLIT_CONFIG_DIR"] = "/tmp/.streamlit"
os.environ["STREAMLIT_CACHE_DIR"] = "/tmp/.streamlit"

# Patch asyncio loop to avoid RuntimeError
import nest_asyncio
nest_asyncio.apply()

import streamlit as st
import requests
import pandas as pd

# Page config
st.set_page_config(page_title="ExtraaLearn Lead Converter", layout="centered")
st.title("πŸŽ“ ExtraaLearn Lead Conversion")
st.write("Enter lead details and click Predict.")

# Inputs
age = st.number_input("Age", 18, 100, 30)
visits = st.number_input("Website Visits", 0, 50, 1)
time_spent = st.number_input("Time Spent on Website (s)", 0, 5000, 300)
pages = st.number_input("Page Views per Visit", 1, 20, 3)
occ = st.selectbox("Current Occupation", ["Professional","Unemployed","Student"])
first_int = st.selectbox("First Interaction", ["Website","Mobile App"])
profile = st.selectbox("Profile Completed", ["Low","Medium","High"])
print1 = st.checkbox("Saw Newspaper Ad")
print2 = st.checkbox("Saw Magazine Ad")
digital = st.checkbox("Saw Digital Ad")
edu_chan = st.checkbox("Heard via Education Channels")
referral = st.checkbox("Heard via Referral")
last_act = st.selectbox("Last Activity", ["Email Activity","Phone Activity","Website Activity"])

if st.button("Predict"):
    payload = {
        "age": age,
        "website_visits": visits,
        "time_spent_on_website": time_spent,
        "page_views_per_visit": pages,
        "current_occupation": occ,
        "first_interaction": first_int,
        "profile_completed": profile,
        "print_media_type1": int(print1),
        "print_media_type2": int(print2),
        "digital_media": int(digital),
        "educational_channels": int(edu_chan),
        "referral": int(referral),
        "last_activity": last_act
    }
    resp = requests.post("$BACKEND_URL", json=payload)
    if resp.ok:
        res = resp.json()
        st.success(f"Conversion: {res['prediction']} (Prob: {res['probability']:.2f})")
    else:
        st.error(f"Error {resp.status_code}: {resp.text}")