sg8kht commited on
Commit
f715f17
Β·
verified Β·
1 Parent(s): 3942d13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -23
app.py CHANGED
@@ -13,10 +13,11 @@ loaded_model = pickle.load(open("classroom_xgb.pkl", 'rb'))
13
  explainer = shap.Explainer(loaded_model) # PLEASE DO NOT CHANGE THIS.
14
 
15
  # Create the main function for server
16
- def main_func(Target, Admission_grade, Curricular_units_2nd_sem_grade, Previous_qualifications, Curricular_units_1st_sem_grade, Course, Curricular_units_2nd_sem_approved, Age_at_enrollment):
17
- new_row = pd.DataFrame.from_dict({'Target':Target, 'Admission grade':Admission_grade,'Curricular units 2nd sem (grade)':Curricular_units_2nd_sem_grade,
18
- 'Previous qualifications':Previous_qualifications,'Curricular units 1st sem (grade)':Curricular_units_1st_sem_grade, 'Course':Course,'Curricular units 2nd sem (approved)':Curricular_units_2nd_sem_approved,
19
- 'Age at enrollment':Age_at_enrollment}).transpose()
 
20
 
21
  prob = loaded_model.predict_proba(new_row)
22
 
@@ -29,11 +30,11 @@ def main_func(Target, Admission_grade, Curricular_units_2nd_sem_grade, Previous_
29
  local_plot = plt.gcf()
30
  plt.close()
31
 
32
- return {"Low Chance": float(prob[0][0]), "High Chance": 1-float(prob[0][0])}, local_plot
33
 
34
  # Create the UI
35
- title = "**Heart Attack Predictor & Interpreter** πŸͺ"
36
- description1 = """This app takes info from subjects and predicts their heart attack likelihood. Do not use for medical diagnosis."""
37
 
38
  description2 = """
39
  To use the app, click on one of the examples, or adjust the values of the factors, and click on Analyze. 🀞
@@ -45,28 +46,28 @@ with gr.Blocks(title=title) as demo:
45
  gr.Markdown("""---""")
46
  gr.Markdown(description2)
47
  gr.Markdown("""---""")
48
-
49
- Curricular_units_2nd_sem_grade = gr.Number(label="Curricular units 2nd sem (grade)", value=40)
50
- Admission_grade = gr.Slider(label="Admission grade", minimum=0, maximum=1, value=1, step=1)
51
- Previous_qualifications = gr.Slider(label="Previous qualifications", minimum=1, maximum=5, value=4, step=1)
52
- Curricular_units_1st_sem_grade = gr.Slider(label="Curricular units 1st sem (grade)", minimum=1, maximum=5, value=4, step=1)
53
- Course = gr.Slider(label="Course", minimum=1, maximum=5, value=4, step=1)
54
- Curricular_units_2nd_sem_approved = gr.Slider(label="Curricular units 2nd sem (approved)", minimum=1, maximum=5, value=4, step=1)
55
- Age_at_enrollment = gr.Slider(label="Age_at_enrollment", minimum=1, maximum=5, value=4, step=1)
56
-
57
- submit_btn = gr.Button("Analyze")
58
 
59
- with gr.Column(visible=True) as output_col:
60
- label = gr.Label(label = "Predicted Label")
61
- local_plot = gr.Plot(label = 'Shap:')
62
 
63
  submit_btn.click(
64
  main_func,
65
- [Admission_grade, Curricular_units_2nd_sem_grade, Previous_qualifications, Curricular_units_1st_sem_grade, Course, Curricular_units_2nd_sem_approved, Age_at_enrollment],
66
- [label,local_plot], api_name="Dropout_Predictor"
67
  )
68
 
69
  gr.Markdown("### Click on any of the examples below to see how it works:")
70
- gr.Examples([[24,0,4,4,5,5,4,4,5,5,1,2,3], [24,0,4,4,5,3,3,2,1,1,1,2,3]], [Admission_grade, Curricular_units_2nd_sem_grade, Previous_qualifications, Curricular_units_1st_sem_grade, Course, Curricular_units_2nd_sem_approved, Age_at_enrollment], [label,local_plot], main_func, cache_examples=True)
71
 
72
  demo.launch()
 
13
  explainer = shap.Explainer(loaded_model) # PLEASE DO NOT CHANGE THIS.
14
 
15
  # Create the main function for server
16
+ def main_func(Target, Admission grade, Curricular units 2nd sem (grade), Previous qualification (grade), Curricular units 1st sem (grade), Course, Curricular units 2nd sem (approved), Age at enrollment):
17
+ new_row = pd.DataFrame.from_dict({'Target':Target,'Admission grade':AdmissionGrade,
18
+ 'Curricular units 2nd sem (grade)':CurricularUnits2ndSemGrade,'Previous qualification (grade)':PreviousQualificationGrade,'Curricular units 1st sem (grade)':CurricularUnits1stSemGrade,
19
+ 'Course':Course,'Curricular units 2nd sem (approved)':CurricularUnits2ndSemApproved,'Age at enrollment':AgeAtEnrollment,
20
+ orient = 'index').transpose()
21
 
22
  prob = loaded_model.predict_proba(new_row)
23
 
 
30
  local_plot = plt.gcf()
31
  plt.close()
32
 
33
+ return {"Dropout": float(prob[0][0]), "Graduate": 1-float(prob[0][0])}, local_plot
34
 
35
  # Create the UI
36
+ title = "**Student Graduation Predictor & Interpreter** πŸͺ"
37
+ description1 = """This app takes info from subjects and predicts their graduation likelihood."""
38
 
39
  description2 = """
40
  To use the app, click on one of the examples, or adjust the values of the factors, and click on Analyze. 🀞
 
46
  gr.Markdown("""---""")
47
  gr.Markdown(description2)
48
  gr.Markdown("""---""")
49
+ with gr.Row():
50
+ with gr.Column():
51
+ Target = gr.Number(label="Target Score", value=40)
52
+ AdmissionGrade = gr.Slider(label="AdmissionGrade Score", minimum=0, maximum=1, value=1, step=1)
53
+ PreviousQualificationGrade = gr.Slider(label="PreviousQualificationGrade Score", minimum=1, maximum=5, value=4, step=1)
54
+ CurricularUnits1stSemGrade = gr.Slider(label="CurricularUnits1stSemGrade Score", minimum=1, maximum=5, value=4, step=1)
55
+ Course = gr.Slider(label="Course Score", minimum=1, maximum=5, value=4, step=1)
56
+ CurricularUnits2ndSemApproved = gr.Slider(label="CurricularUnits2ndSemApproved Score", minimum=1, maximum=5, value=4, step=1)
57
+ AgeAtEnrollment = gr.Slider(label="AgeAtEnrollment Score", minimum=1, maximum=5, value=4, step=1)
58
+ submit_btn = gr.Button("Analyze")
59
 
60
+ with gr.Column(visible=True) as output_col:
61
+ label = gr.Label(label = "Predicted Label")
62
+ local_plot = gr.Plot(label = 'Shap:')
63
 
64
  submit_btn.click(
65
  main_func,
66
+ [Target, AdmissionGrade, CurricularUnits2ndSemGrade, PreviousQualificationGrade, CurricularUnits1stSemGrade, Course, CurricularUnits2ndSemApproved, AgeAtEnrollment],
67
+ [label,local_plot], api_name="Graduation_Predictor"
68
  )
69
 
70
  gr.Markdown("### Click on any of the examples below to see how it works:")
71
+ gr.Examples([['Graduate',],119.6,13.000000,122.0,9773,5,18], [Target, AdmissionGrade, CurricularUnits2ndSemGrade, PreviousQualificationGrade, CurricularUnits1stSemGrade, Course, CurricularUnits2ndSemApproved, AgeAtEnrollment], [label,local_plot], main_func, cache_examples=True)
72
 
73
  demo.launch()