File size: 2,003 Bytes
3c8c0e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import streamlit as st
from src.pipeline.predict_pipeline import CustomData, PredictPipeline

# Application title
st.set_page_config(page_title="Math Score Predictor")
st.title("Student Math Score Predictor")
st.write("This application predicts math scores based on student data.")

# Input form
with st.form(key="student_form"):
    gender = st.selectbox("Gender", options=["male", "female"])
    ethnicity = st.selectbox(
        "Race or Ethnicity",
        options=["group A", "group B", "group C", "group D", "group E"],
    )
    parental_education = st.selectbox(
        "Parental Level of Education",
        options=[
            "associate's degree",
            "bachelor's degree",
            "high school",
            "master's degree",
            "some college",
            "some high school",
        ],
    )
    lunch = st.selectbox("Lunch Type", options=["free/reduced", "standard"])
    test_preparation_course = st.selectbox(
        "Test Preparation Course", options=["none", "completed"]
    )

    reading_score = st.number_input(
        "Reading Score (out of 100)", min_value=0, max_value=100, step=1
    )
    writing_score = st.number_input(
        "Writing Score (out of 100)", min_value=0, max_value=100, step=1
    )

    # Submit button
    submit_button = st.form_submit_button("Predict Exam Scores")

# Process prediction when button is pressed
if submit_button:
    # Initialize data
    data = CustomData(
        gender=gender,
        race_ethnicity=ethnicity,
        parental_level_of_education=parental_education,
        lunch=lunch,
        test_preparation_course=test_preparation_course,
        reading_score=reading_score,
        writing_score=writing_score,
    )

    # Get data as DataFrame
    pred_df = data.get_data_as_dataframe()

    # Make predictions
    predict_pipeline = PredictPipeline()
    results = predict_pipeline.predict(pred_df)

    # Display prediction result
    st.success(f"The predicted Maths Score is {results[0]:.2f}")