Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests, os | |
| st.set_page_config( | |
| page_title="ChildCare Revenue Predictor", | |
| page_icon="๐ซ", | |
| layout="wide", | |
| ) | |
| st.title("๐ซ ChildCare Facility Revenue Predictor") | |
| st.markdown(""" | |
| Predict the **monthly revenue** a child will generate for a day care facility, | |
| based on child profile, program enrolment, and facility characteristics. | |
| Fill in the details below and click **Predict Revenue**. | |
| """) | |
| BACKEND_URL = os.environ.get( | |
| "BACKEND_URL", | |
| "https://ramzai9-childcareprediction.hf.space" | |
| ) | |
| with st.sidebar: | |
| st.header("โน๏ธ How to Use") | |
| st.markdown(""" | |
| 1. Enter the child's details in the **Child Profile** section. | |
| 2. Enter the facility details in the **Facility Details** section. | |
| 3. Click **Predict Revenue** to get the model's estimate. | |
| **Field Guide:** | |
| - **Child Age** โ child's current age in months (6 = 6 months, 60 = 5 years) | |
| - **Care Program** โ Full Day covers 8+ hours; Half Day covers 4โ5 hours; After School is 3โ4 hours after school | |
| - **Attendance Rate** โ proportion of days the child attends (1.0 = never absent) | |
| - **Monthly Fee** โ the fee charged per month in USD | |
| - **Child ID Prefix** โ two-letter code derived from program (FD, HD, AS) | |
| - **Activity Category** โ primary activity type the child is enrolled in | |
| """) | |
| st.divider() | |
| st.markdown("**Backend API:**") | |
| st.code(BACKEND_URL, language=None) | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.subheader("๐ถ Child Profile") | |
| child_age = st.number_input( | |
| "Child Age (months)", | |
| min_value=0.0, max_value=120.0, value=36.0, step=1.0, | |
| help="Enter the child's age in months. E.g. 24 = 2 years old.", | |
| ) | |
| care_program = st.selectbox( | |
| "Care Program", | |
| options=["Full Day", "Half Day", "After School"], | |
| help="Full Day (8+ hrs), Half Day (4โ5 hrs), After School (3โ4 hrs after school).", | |
| ) | |
| attendance_rate = st.slider( | |
| "Attendance Rate", | |
| min_value=0.50, max_value=1.00, value=0.85, step=0.01, | |
| help="Proportion of scheduled days the child attends. 1.0 = 100% attendance.", | |
| ) | |
| monthly_fee = st.number_input( | |
| "Monthly Fee ($)", | |
| min_value=0.0, max_value=10000.0, value=2000.0, step=50.0, | |
| help="The monthly fee charged for the child's enrolment, in USD.", | |
| ) | |
| child_id_char = st.selectbox( | |
| "Child ID Prefix", | |
| options=["FD", "HD", "AS"], | |
| help="FD = Full Day, HD = Half Day, AS = After School.", | |
| ) | |
| activity_category = st.selectbox( | |
| "Activity Type Category", | |
| options=["Academic", "Creative", "Wellness"], | |
| help="Academic: Reading, Math, STEM. Creative: Arts, Music, Dance. Wellness: PE, Yoga, Outdoor Play.", | |
| ) | |
| with col2: | |
| st.subheader("๐ข Facility Details") | |
| facility_size = st.selectbox( | |
| "Facility Size", | |
| options=["Small", "Medium", "Large"], | |
| help="Small (<30 children), Medium (30โ80 children), Large (80+ children).", | |
| ) | |
| city_type = st.selectbox( | |
| "City Type", | |
| options=["Tier 1", "Tier 2", "Tier 3"], | |
| help="Tier 1 = major metropolitan area. Tier 2 = mid-sized city. Tier 3 = small town or rural.", | |
| ) | |
| facility_type = st.selectbox( | |
| "Facility Type", | |
| options=["Full-Service Center", "Montessori School", "Home Daycare", "Corporate Daycare"], | |
| help="Type of facility offering child care services.", | |
| ) | |
| facility_year = st.number_input( | |
| "Facility Establishment Year", | |
| min_value=1900, max_value=2100, value=2005, step=1, | |
| help="The year the facility was established. Older facilities may have more established reputations.", | |
| ) | |
| st.divider() | |
| predict_btn = st.button("๐ฎ Predict Revenue", type="primary", use_container_width=True) | |
| if predict_btn: | |
| payload = { | |
| "Child_Age_Months": child_age, | |
| "Child_Care_Program": care_program, | |
| "Child_Attendance_Rate": attendance_rate, | |
| "Child_Monthly_Fee": monthly_fee, | |
| "Facility_Size": facility_size, | |
| "Facility_Location_City_Type": city_type, | |
| "Facility_Type": facility_type, | |
| "Child_Id_char": child_id_char, | |
| "Facility_Establishment_Year": facility_year, | |
| "Activity_Type_Category": activity_category, | |
| } | |
| with st.spinner("Contacting the prediction API..."): | |
| try: | |
| resp = requests.post( | |
| f"{BACKEND_URL}/v1/predict", | |
| json=payload, | |
| timeout=30, | |
| ) | |
| if resp.status_code == 200: | |
| revenue = resp.json().get("Revenue", "N/A") | |
| st.success(f"### ๐ฐ Predicted Monthly Revenue: **${revenue:,.2f}**") | |
| st.balloons() | |
| with st.expander("๐ Input Summary"): | |
| st.json(payload) | |
| else: | |
| st.error(f"API Error ({resp.status_code}): {resp.json().get('error', resp.text)}") | |
| except requests.exceptions.Timeout: | |
| st.error("โฑ๏ธ Request timed out. The backend may be starting up โ please try again in 30 seconds.") | |
| except requests.exceptions.ConnectionError: | |
| st.error("๐ Could not connect to the backend. Please verify the BACKEND_URL environment variable.") | |
| except Exception as e: | |
| st.error(f"Unexpected error: {e}") | |
| st.divider() | |
| st.caption("Built with XGBoost + Flask + Streamlit ยท Deployed on Hugging Face Spaces") | |