EAV123 commited on
Commit
00ce994
·
verified ·
1 Parent(s): 722a078

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -1,15 +1,25 @@
1
  import streamlit as st
2
  import pickle
3
  import numpy as np
 
4
 
5
- # Load the saved model
6
  with open('rf_model.pkl', 'rb') as file:
7
- model = pickle.load(file)
 
 
8
 
9
  # Define the function to make predictions
10
- def make_prediction(model, input_data):
11
- prediction = model.predict(input_data)
12
- return prediction
 
 
 
 
 
 
 
13
 
14
  # Define the function to calculate GPA
15
  def calculate_gpa(total_score):
@@ -32,7 +42,7 @@ def main():
32
  # Add a title and description
33
  st.title("Exam Score Prediction")
34
  st.markdown(
35
- "This app predicts exam scores based on input features such as level, course units, attendance, mid-semester score, and assignments."
36
  )
37
 
38
  # Create input fields
@@ -49,17 +59,17 @@ def main():
49
  if st.button("Predict Exam Score"):
50
  # Add total_score to the input data
51
  input_data = np.array([[level, course_units, attendance, mid_semester, assignments]])
52
- prediction = make_prediction(model, input_data)
53
 
54
  # Calculate total score
55
  total_score = attendance + mid_semester + assignments + prediction[0]
56
 
57
  st.write(f"Predicted Exam Score: {prediction[0]:.2f}")
58
  st.write(f"Total Score: {total_score}")
59
-
60
  # Calculate GPA
61
  gpa = calculate_gpa(total_score)
62
  st.write(f"Predicted GPA: {gpa}")
63
 
64
  if __name__ == '__main__':
65
- main()
 
1
  import streamlit as st
2
  import pickle
3
  import numpy as np
4
+ from tensorflow.keras.models import load_model
5
 
6
+ # Load the saved models
7
  with open('rf_model.pkl', 'rb') as file:
8
+ rf_model = pickle.load(file)
9
+
10
+ reloaded_model = load_model('deep_model.h5')
11
 
12
  # Define the function to make predictions
13
+ def make_prediction(rf_model, nn_model, input_data):
14
+ # Predictions from RandomForestRegressor
15
+ rf_predictions = rf_model.predict(input_data)
16
+
17
+ # Predictions from Neural Network model
18
+ nn_predictions = nn_model.predict(input_data).flatten()
19
+
20
+ # Combine predictions
21
+ combined_predictions = (rf_predictions + nn_predictions) / 2 # Taking the average of predictions
22
+ return combined_predictions
23
 
24
  # Define the function to calculate GPA
25
  def calculate_gpa(total_score):
 
42
  # Add a title and description
43
  st.title("Exam Score Prediction")
44
  st.markdown(
45
+ "This app predicts exam scores based on input features such as level, course units, attendance, mid-semester score, and assignments using a combined model."
46
  )
47
 
48
  # Create input fields
 
59
  if st.button("Predict Exam Score"):
60
  # Add total_score to the input data
61
  input_data = np.array([[level, course_units, attendance, mid_semester, assignments]])
62
+ prediction = make_prediction(rf_model, reloaded_model, input_data)
63
 
64
  # Calculate total score
65
  total_score = attendance + mid_semester + assignments + prediction[0]
66
 
67
  st.write(f"Predicted Exam Score: {prediction[0]:.2f}")
68
  st.write(f"Total Score: {total_score}")
69
+
70
  # Calculate GPA
71
  gpa = calculate_gpa(total_score)
72
  st.write(f"Predicted GPA: {gpa}")
73
 
74
  if __name__ == '__main__':
75
+ main()