myexperiments / app.py
Ashexperiments's picture
Upload folder using huggingface_hub
b656290 verified
raw
history blame
2.89 kB
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}")