import streamlit as st import pickle import sklearn import pandas as pd # Load trained model, encoders, and feature column order with open("best_model.pkl", "rb") as f: model = pickle.load(f) with open("encoders.pkl", "rb") as f: encoders = pickle.load(f) with open("columns.pkl", "rb") as f: feature_columns = pickle.load(f) st.title("🧠 Autism Prediction System") st.markdown("### 📝 Please fill the following details:") # A1 to A10 - Screening Scores user_inputs = { "A1_Score": st.selectbox("A1 Score (Social interaction)", [0, 1]), "A2_Score": st.selectbox("A2 Score (Eye contact)", [0, 1]), "A3_Score": st.selectbox("A3 Score (Responds to name)", [0, 1]), "A4_Score": st.selectbox("A4 Score (Repetitive behavior)", [0, 1]), "A5_Score": st.selectbox("A5 Score (Preference for routine)", [0, 1]), "A6_Score": st.selectbox("A6 Score (Sensitive to sounds, lights, etc.)", [0, 1]), "A7_Score": st.selectbox("A7 Score (Speech or communication delay)", [0, 1]), "A8_Score": st.selectbox("A8 Score (Struggles recognizing emotions)", [0, 1]), "A9_Score": st.selectbox("A9 Score (Unusual interests or fixations)", [0, 1]), "A10_Score": st.selectbox("A10 Score (Strong attention to detail)", [0, 1]), # Demographic and medical history "age": st.number_input("Age (in years)", min_value=1, max_value=120), "gender": st.selectbox("Gender (Biological sex)", encoders["gender"].classes_), "ethnicity": st.selectbox("Ethnicity (Cultural background)", encoders["ethnicity"].classes_), "jaundice": st.selectbox("Jaundice at Birth (Medical history)", encoders["jaundice"].classes_), "contry_of_res": st.selectbox("Country of Residence (Current location)", encoders["contry_of_res"].classes_), "austim": st.selectbox("Family history of Autism?", encoders["austim"].classes_), "used_app_before": st.selectbox("Used Screening App Before?", encoders["used_app_before"].classes_), "result": st.number_input("Screening Score Result (Total score from A1-A10)", min_value=0, max_value=20), "relation": st.selectbox("Relation to Patient (Who is filling this form?)", encoders["relation"].classes_), } if st.button("🔍 Predict"): try: # Convert to DataFrame input_df = pd.DataFrame([user_inputs]) # Encode categorical columns for col in encoders: input_df[col] = encoders[col].transform(input_df[col]) # Reorder columns as used in training input_df = input_df[feature_columns] # Predict prediction = model.predict(input_df)[0] result = "🧠 ASD Positive" if prediction == 1 else "✅ ASD Negative" st.success(f"Prediction: {result}") except Exception as e: st.error(f"⚠️ Error during prediction: {e}")