anshharora commited on
Commit
b503408
·
verified ·
1 Parent(s): 3245ea4

Upload 6 files

Browse files
final_marks_predictor_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71af81115fe9300d43f41356ed4b5b9715031c79c91e655696bd20a94394ae89
3
+ size 164704
final_model.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
gradio_app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import warnings
3
+ import numpy as np
4
+ import pandas as pd
5
+ from tensorflow.keras.models import load_model
6
+ import pickle
7
+ from dotenv import load_dotenv
8
+ import gradio as gr
9
+
10
+ # Suppress TensorFlow and other warnings
11
+ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
12
+ warnings.filterwarnings("ignore")
13
+
14
+ # Load environment variables
15
+ load_dotenv()
16
+
17
+ # Load the trained model and scaler
18
+ model = None
19
+ scaler = None
20
+
21
+ def load_model_and_scaler():
22
+ global model, scaler
23
+ try:
24
+ model = load_model('final_marks_predictor_model.h5')
25
+ with open('scaler.pkl', 'rb') as f:
26
+ scaler = pickle.load(f)
27
+ except Exception as e:
28
+ print(f"Error loading model or scaler: {e}")
29
+
30
+ # Load model and scaler when the application starts
31
+ load_model_and_scaler()
32
+
33
+ def predict_new_input(age, year1_marks, year2_marks, studytime, failures):
34
+ try:
35
+ feature_names = ['age', 'year1_marks', 'year2_marks', 'studytime', 'failures']
36
+ new_input_df = pd.DataFrame([[age, year1_marks, year2_marks, studytime, failures]], columns=feature_names)
37
+
38
+ if model is None or scaler is None:
39
+ return "Model or scaler is not loaded."
40
+
41
+ new_input_scaled = scaler.transform(new_input_df)
42
+ predicted_marks = model.predict(new_input_scaled, verbose=0)
43
+ return round(float(predicted_marks[0][0]), 2)
44
+ except Exception as e:
45
+ print(f"Error during prediction: {e}")
46
+ return "Error during prediction"
47
+
48
+ # Define Gradio Interface
49
+ def gradio_predict(age, year1_marks, year2_marks, studytime, failures):
50
+ return predict_new_input(age, year1_marks, year2_marks, studytime, failures)
51
+
52
+ if __name__ == '__main__':
53
+ # Create the Gradio interface
54
+ with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {max-width: 600px; margin: auto; padding: 20px; border: 1px solid #e0e0e0; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);}") as interface:
55
+ with gr.Column():
56
+ gr.Markdown("## Student Performance Prediction")
57
+ gr.Markdown("Please fill in all the required fields and click 'Predict' to see your final predicted marks.")
58
+
59
+ # Create form fields
60
+ with gr.Row():
61
+ age = gr.Number(label="Age", interactive=True, elem_id="age-input")
62
+ with gr.Row():
63
+ year1_marks = gr.Number(label="First Year Marks", interactive=True, elem_id="year1-input")
64
+ with gr.Row():
65
+ year2_marks = gr.Number(label="Second Year Marks", interactive=True, elem_id="year2-input")
66
+ with gr.Row():
67
+ studytime = gr.Number(label="Study Time (hours/week)", interactive=True, elem_id="studytime-input")
68
+ with gr.Row():
69
+ failures = gr.Number(label="Number of Failures", interactive=True, elem_id="failures-input")
70
+
71
+ submit_button = gr.Button("Predict", elem_id="predict-button", variant="primary")
72
+
73
+ # Create output display
74
+ output = gr.Textbox(label="Predicted Final Marks", interactive=False, elem_id="output-box")
75
+
76
+ # Button action
77
+ submit_button.click(gradio_predict, inputs=[age, year1_marks, year2_marks, studytime, failures], outputs=output)
78
+
79
+ interface.launch(share=False)
modified_student_data.csv ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
Binary file (2.12 kB). View file
 
scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc73054ed7b77ea17d44da0f43009a7f5344b605aca2bc693fd6333e7f6665f7
3
+ size 713