raakibul commited on
Commit
c5ebab0
·
verified ·
1 Parent(s): eee8679

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -57
app.py CHANGED
@@ -1,58 +1,58 @@
1
- #gradio app
2
- import gradio as gr
3
- import pandas as pd
4
- import pickle
5
- import numpy as np
6
-
7
- # Load the Model
8
- with open("student_rf_pipeline.pkl", "rb") as f:
9
- model = pickle.load(f)
10
-
11
- # The Logic Function
12
- def predict_gpa(gender, age, address, famsize,
13
- Pstatus, M_Edu, F_Edu, M_Job, F_Job,
14
- relationship, smoker, tuition_fee, time_friends,
15
- ssc_result):
16
-
17
- input_df = pd.DataFrame([[
18
- gender, age, address, famsize, Pstatus,
19
- M_Edu, F_Edu, M_Job, F_Job, relationship,
20
- smoker, tuition_fee, time_friends, ssc_result
21
-
22
- ]],
23
- columns=[
24
- 'gender', 'age', 'address', 'famsize', 'Pstatus', 'M_Edu', 'F_Edu', 'M_Job', 'F_Job', 'relationship', 'smoker', 'tuition_fee', 'time_friends', 'ssc_result'
25
- ])
26
-
27
- # Predict
28
- prediction = model.predict(input_df)[0]
29
-
30
- # Return formatted result (Clipped 0-5)
31
- return f"Predicted HSC Result: {np.clip(prediction, 0, 5):.2f}"
32
-
33
- # 3. The App Interface
34
-
35
- inputs = [
36
- gr.Radio(["M", "F"], label="Gender"),
37
- gr.Number(label="Age", value=18),
38
- gr.Radio(["Urban", "Rural"], label="Address"),
39
- gr.Radio(["GT3", "LE3"], label="Family Size"),
40
- gr.Radio(["Together", "Apart"], label="Parent Status"),
41
- gr.Slider(0, 4, step=1, label="Mother's Edu"),
42
- gr.Slider(0, 4, step=1, label="Father's Edu"),
43
- gr.Dropdown(["At_home", "Health", "Other", "Services", "Teacher"], label="Mother's Job"),
44
- gr.Dropdown(["Teacher", "Other", "Services", "Health", "Business", "Farmer"], label="Father's Job"),
45
- gr.Radio(["Yes", "No"], label="Relationship"),
46
- gr.Radio(["Yes", "No"], label="Smoker"),
47
- gr.Number(label="Tuition Fee"),
48
- gr.Slider(1, 5, step=1, label="Time with Friends"),
49
- gr.Number(label="SSC Result (GPA)")
50
- ]
51
-
52
- app = gr.Interface(
53
- fn=predict_gpa,
54
- inputs=inputs,
55
- outputs="text",
56
- title="Student HSC Result Predictor")
57
-
58
  app.launch(share=True)
 
1
+ #gradio app
2
+ import gradio as gr
3
+ import pandas as pd
4
+ import pickle
5
+ import numpy as np
6
+
7
+ # Load the Model
8
+ with open("student_rf_pipeline.pkl", "rb") as f:
9
+ model = pickle.load(f)
10
+
11
+ # The Logic Function
12
+ def predict_gpa(gender, age, address, famsize,
13
+ Pstatus, M_Edu, F_Edu, M_Job, F_Job,
14
+ relationship, smoker, tuition_fee, time_friends,
15
+ ssc_result):
16
+
17
+ input_df = pd.DataFrame([[
18
+ gender, age, address, famsize, Pstatus,
19
+ M_Edu, F_Edu, M_Job, F_Job, relationship,
20
+ smoker, tuition_fee, time_friends, ssc_result
21
+
22
+ ]],
23
+ columns=[
24
+ 'gender', 'age', 'address', 'famsize', 'Pstatus', 'M_Edu', 'F_Edu', 'M_Job', 'F_Job', 'relationship', 'smoker', 'tuition_fee', 'time_friends', 'ssc_result'
25
+ ])
26
+
27
+ # Predict
28
+ prediction = model.predict(input_df)[0]
29
+
30
+ # Return formatted result (Clipped 0-5)
31
+ return f"Predicted HSC Result: {np.clip(prediction, 0, 5):.2f}"
32
+
33
+ # 3. The App Interface
34
+
35
+ inputs = [
36
+ gr.Radio(["M", "F"], label="Gender"),
37
+ gr.Number(label="Age", value=18),
38
+ gr.Radio(["Urban", "Rural"], label="Address"),
39
+ gr.Radio(["GT3", "LE3"], label="Family Size"),
40
+ gr.Radio(["Together", "Apart"], label="Parent Status"),
41
+ gr.Slider(0, 4, step=1, label="Mother's Edu"),
42
+ gr.Slider(0, 4, step=1, label="Father's Edu"),
43
+ gr.Dropdown(["At_home", "Health", "Other", "Services", "Teacher"], label="Mother's Job"),
44
+ gr.Dropdown(["Teacher", "Other", "Services", "Health", "Business", "Farmer"], label="Father's Job"),
45
+ gr.Radio(["Yes", "No"], label="Relationship"),
46
+ gr.Radio(["Yes", "No"], label="Smoker"),
47
+ gr.Number(label="Tuition Fee"),
48
+ gr.Slider(1, 5, step=1, label="Time with Friends"),
49
+ gr.Number(label="SSC Result (GPA)")
50
+ ]
51
+
52
+ app = gr.Interface(
53
+ fn=predict_gpa,
54
+ inputs=inputs,
55
+ outputs="text",
56
+ title="Student's HSC Result Predictor")
57
+
58
  app.launch(share=True)