CoolFace
Apppublic

mby026/Alcohol_Effects

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py89 linesDownload Raw Back to root
1import joblib2import pandas as pd3import streamlit as st 4 5sex_dict = {'Female': 0, 'Male': 1}6address_dict = {'Urban': 0, 'Rural':1}7famsize_dict = {'Greater than 3': 0, 'Less than or equal to 3': 1}8Pstatus_dict = {'Living together': 0, 'Apart': 1}9Mjob_dict = {'at_home': 0, 'health': 1, 'other': 1, 'services': 1, 'teacher': 1}10Fjob_dict = {'at_home': 0, 'health': 1, 'other': 1, 'services': 1, 'teacher': 1}11schoolsup_dict = {'no': 0, 'yes': 1}12famsup_dict = {'no': 0, 'yes': 1}13activities_dict = {'no': 0, 'yes': 1}14higher_dict = {'no': 0, 'yes': 1}15romantic_dict = {'no': 0, 'yes': 1}16 17model = joblib.load('model.joblib')18unique_values = joblib.load('unique_values.joblib')19 20unique_sex =  unique_values["sex"]21unique_address =  unique_values["address"]22unique_famsize =  unique_values["famsize"]23unique_Pstatus =  unique_values["Pstatus"]24unique_Mjob =  unique_values["Mjob"]25unique_Fjob = unique_values["Fjob"]26unique_schoolsup =  unique_values["schoolsup"]27unique_famsup =  unique_values["famsup"]28unique_activities = unique_values["activities"]29unique_higher =  unique_values["higher"]30unique_romantic = unique_values["romantic"]31 32def main():33    st.title("Predict Score")34 35    with st.form("questionnaire"):36 37        age = st.slider("student's age", min_value=0, max_value=100)38        studytime = st.slider("weekly study time", min_value=0, max_value=10)39        famrel = st.slider("quality of family relationships (from 1 - very bad to 5 - excellent)", min_value=1, max_value=5)40        goout = st.slider("going out with friends (from 1 - very low to 5 - very high)", min_value=1, max_value=5)41        Dalc = st.slider("workday alcohol consumption (from 1 - very low to 5 - very high)", min_value=1, max_value=5)42        Walc = st.slider("weekend alcohol consumption (from 1 - very low to 5 - very high)", min_value=1, max_value=5)43        health = st.slider("current health status (from 1 - very bad to 5 - very good)", min_value=1, max_value=5)44        freetime = st.slider("free time after school (from 1 - very low to 5 - very high)", min_value=1, max_value=5)45        absences = st.slider("number of school absences", min_value=0, max_value=100)46 47        sex = st.selectbox("student's sex", unique_sex)48        address = st.selectbox("student's home address type", unique_address)49        famsize = st.selectbox("family size", unique_famsize)50        Pstatus = st.selectbox("parent's cohabitation status", unique_Pstatus)51        Mjob = st.selectbox("mother's job", unique_Mjob)52        Fjob = st.selectbox("father's job", unique_Fjob)53        schoolsup = st.selectbox("extra educational support", unique_schoolsup)54        famsup = st.selectbox("family educational support", unique_famsup)55        activities = st.selectbox("extra-curricular activities", unique_activities)56        higher = st.selectbox("wants to take higher education", unique_higher)57        romantic = st.selectbox("with a romantic relationship", unique_romantic)58 59        clicked = st.form_submit_button("Predict Student's Score")60        61        if clicked:62            result = model.predict(pd.DataFrame({63                "age": [age],64                "studytime": [studytime],65                "famrel": [famrel],66                "goout": [goout],67                "Dalc": [Dalc],68                "Walc": [Walc],69                "health": [health],70                "freetime": [freetime],71                "absences": [absences],72                "sex": [sex_dict[sex]],73                "address": [address_dict[address]],74                "famsize": [famsize_dict[famsize]],75                "Pstatus": [Pstatus_dict[Pstatus]],76                "Mjob": [Mjob_dict[Mjob]],77                "Fjob": [Fjob_dict[Fjob]],78                "schoolsup": [schoolsup_dict[schoolsup]],79                "famsup": [famsup_dict[famsup]],80                "activities": [activities_dict[activities]],81                "higher": [higher_dict[higher]],82                "romantic": [romantic_dict[romantic]]83            }))84            result = result[0]85            st.success('The predicted score is {:.2f}'.format(round(result, 2)))86 87if __name__=='__main__':88    main()89