Spaces:
Sleeping
Sleeping
Download app.py from HSSHETTY01/Extraa-Learn-frontend: direct link, hf CLI and curl.
- Browser
- Download file 2.98 kB
-
https://huggingface.co/spaces/HSSHETTY01/Extraa-Learn-frontend/resolve/main/app.py
- Command line
-
hf download hf://spaces/HSSHETTY01/Extraa-Learn-frontend/app.py
-
curl -L -o app.py https://huggingface.co/spaces/HSSHETTY01/Extraa-Learn-frontend/resolve/main/app.py
2.98 kB
| # 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" # Corrected URL for capitalization | |
| #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}") | |