Spaces:
Runtime error
Runtime error
File size: 2,889 Bytes
205ca7f b656290 205ca7f b656290 205ca7f b656290 205ca7f b656290 205ca7f b656290 205ca7f b656290 205ca7f b656290 205ca7f b656290 205ca7f |
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 71 72 |
import streamlit as st
import requests
import json
st.title("Lead Conversion Prediction")
st.write("Enter the lead details to predict conversion likelihood.")
# Input fields for lead features (replace with your actual features)
age = st.number_input("Age", min_value=0)
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'])
website_visits = st.number_input("Website Visits", min_value=0)
time_spent_on_website = st.number_input("Time Spent on Website (seconds)", min_value=0)
page_views_per_visit = st.number_input("Page Views per Visit", min_value=0.0)
last_activity = st.selectbox("Last Activity", ['Email Activity', 'Website Activity', 'Phone Activity'])
print_media_type1 = st.selectbox("Print Media Type 1", ['Yes', 'No'])
print_media_type2 = st.selectbox("Print Media Type 2", ['Yes', 'No'])
digital_media = st.selectbox("Digital Media", ['Yes', 'No'])
educational_channels = st.selectbox("Educational Channels", ['Yes', 'No'])
referral = st.selectbox("Referral", ['Yes', 'No'])
# Create a dictionary with the input data
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': [print_media_type1],
'print_media_type2': [print_media_type2],
'digital_media': [digital_media],
'educational_channels': [educational_channels],
'referral': [referral]
}
# Convert input data to a list of dictionaries (required by the backend)
input_data_list = [dict(zip(input_data, t)) for t in zip(*input_data.values())]
# Button to trigger prediction
if st.button("Predict Conversion"):
# Replace with the URL of your deployed backend API
backend_url = "YOUR_BACKEND_API_URL/predict" # e.g., "https://your-username-your-backend-space.hf.space/predict"
try:
# Send a POST request to the backend API
response = requests.post(backend_url, json=input_data_list)
if response.status_code == 200:
predictions = response.json()
prediction = predictions[0] # Assuming the backend returns a list with a single prediction
if prediction == 1:
st.success("This lead is likely to convert!")
else:
st.warning("This lead is less likely to convert.")
else:
st.error(f"Error from backend: {response.status_code}")
st.error(response.text)
except Exception as e:
st.error(f"An error occurred: {e}")
|