Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -16,14 +16,13 @@ time_spent_on_website = st.number_input("Time Spent on Website (seconds)", min_v
|
|
| 16 |
page_views_per_visit = st.number_input("Page Views Per Visit", min_value=0.0, value=3.0)
|
| 17 |
last_activity = st.selectbox("Last Activity", ["Email Activity", "Phone Activity", "Website Activity"])
|
| 18 |
|
| 19 |
-
# Marketing Channels
|
| 20 |
print_media_type1 = st.selectbox("Saw Ad in Newspaper?", ["Yes", "No"], index=1)
|
| 21 |
print_media_type2 = st.selectbox("Saw Ad in Magazine?", ["Yes", "No"], index=1)
|
| 22 |
digital_media = st.selectbox("Saw Ad on Digital Platforms?", ["Yes", "No"], index=1)
|
| 23 |
educational_channels = st.selectbox("Heard via Educational Channels?", ["Yes", "No"], index=1)
|
| 24 |
referral = st.selectbox("Heard via Referral?", ["Yes", "No"], index=1)
|
| 25 |
|
| 26 |
-
# Prepare the data dictionary for the API
|
| 27 |
lead_data = {
|
| 28 |
"age": age,
|
| 29 |
"current_occupation": current_occupation,
|
|
@@ -41,21 +40,23 @@ lead_data = {
|
|
| 41 |
}
|
| 42 |
|
| 43 |
if st.button("Predict Propensity", type='primary'):
|
| 44 |
-
|
| 45 |
-
api_url = "https://sirisha335-extraalearn-api.hf.space/v1/predict" # Assuming the endpoint name remains /v1/predict
|
| 46 |
|
| 47 |
-
with st.spinner("Connecting to API..."):
|
| 48 |
try:
|
| 49 |
-
|
|
|
|
| 50 |
if response.status_code == 200:
|
| 51 |
result = response.json()
|
| 52 |
-
prediction = result.get("Conversion_Probability", 0)
|
| 53 |
st.metric("Conversion Propensity", f"{prediction:.4f}")
|
| 54 |
if prediction > 0.5:
|
| 55 |
st.success("This lead is highly likely to convert!")
|
| 56 |
-
else:
|
| 57 |
st.warning("This lead has a low probability of conversion.")
|
| 58 |
else:
|
| 59 |
st.error(f"API Error: {response.status_code} - {response.text}")
|
|
|
|
|
|
|
| 60 |
except Exception as e:
|
| 61 |
-
st.error(f"Could not connect to the backend.
|
|
|
|
| 16 |
page_views_per_visit = st.number_input("Page Views Per Visit", min_value=0.0, value=3.0)
|
| 17 |
last_activity = st.selectbox("Last Activity", ["Email Activity", "Phone Activity", "Website Activity"])
|
| 18 |
|
| 19 |
+
# Marketing Channels
|
| 20 |
print_media_type1 = st.selectbox("Saw Ad in Newspaper?", ["Yes", "No"], index=1)
|
| 21 |
print_media_type2 = st.selectbox("Saw Ad in Magazine?", ["Yes", "No"], index=1)
|
| 22 |
digital_media = st.selectbox("Saw Ad on Digital Platforms?", ["Yes", "No"], index=1)
|
| 23 |
educational_channels = st.selectbox("Heard via Educational Channels?", ["Yes", "No"], index=1)
|
| 24 |
referral = st.selectbox("Heard via Referral?", ["Yes", "No"], index=1)
|
| 25 |
|
|
|
|
| 26 |
lead_data = {
|
| 27 |
"age": age,
|
| 28 |
"current_occupation": current_occupation,
|
|
|
|
| 40 |
}
|
| 41 |
|
| 42 |
if st.button("Predict Propensity", type='primary'):
|
| 43 |
+
api_url = "https://sirisha335-extraalearn-api.hf.space/v1/predict"
|
|
|
|
| 44 |
|
| 45 |
+
with st.spinner("Connecting to API (this may take 20s if the backend is waking up)..."):
|
| 46 |
try:
|
| 47 |
+
# Increased timeout to 20 seconds to allow for cold starts
|
| 48 |
+
response = requests.post(api_url, json=lead_data, timeout=20)
|
| 49 |
if response.status_code == 200:
|
| 50 |
result = response.json()
|
| 51 |
+
prediction = result.get("Conversion_Probability", 0)
|
| 52 |
st.metric("Conversion Propensity", f"{prediction:.4f}")
|
| 53 |
if prediction > 0.5:
|
| 54 |
st.success("This lead is highly likely to convert!")
|
| 55 |
+
else:
|
| 56 |
st.warning("This lead has a low probability of conversion.")
|
| 57 |
else:
|
| 58 |
st.error(f"API Error: {response.status_code} - {response.text}")
|
| 59 |
+
except requests.exceptions.Timeout:
|
| 60 |
+
st.error("The request timed out. The backend Space is likely still starting up or under heavy load. Please try again in a minute.")
|
| 61 |
except Exception as e:
|
| 62 |
+
st.error(f"Could not connect to the backend. Ensure the Backend Space is 'Running'. Error: {e}")
|