Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pickle | |
import numpy as np | |
from tensorflow.keras.models import load_model | |
# Load the saved models | |
with open('rf_model.pkl', 'rb') as file: | |
rf_model = pickle.load(file) | |
reloaded_model = load_model('deep_model.h5') | |
# Define the function to make predictions | |
def make_prediction(rf_model, nn_model, input_data): | |
# Predictions from RandomForestRegressor | |
rf_predictions = rf_model.predict(input_data) | |
# Predictions from Neural Network model | |
nn_predictions = nn_model.predict(input_data).flatten() | |
# Combine predictions | |
combined_predictions = (rf_predictions + nn_predictions) / 2 # Taking the average of predictions | |
return combined_predictions | |
# Define the function to calculate GPA | |
def calculate_gpa(total_score): | |
if total_score >= 70: | |
return 'A (5 points)' | |
elif total_score >= 60: | |
return 'B (4 points)' | |
elif total_score >= 50: | |
return 'C (3 points)' | |
elif total_score >= 45: | |
return 'D (2 points)' | |
else: | |
return 'F (0 points)' | |
# Create the Streamlit app | |
def main(): | |
# Set page title and configure layout | |
st.set_page_config(page_title="Exam Score Prediction", layout="wide") | |
# Add a title and description | |
st.title("Exam Score Prediction") | |
st.markdown( | |
"This app predicts exam scores based on input features such as level, course units, attendance, mid-semester score, and assignments using a combined model." | |
) | |
# Create input fields | |
col1, col2 = st.columns(2) | |
with col1: | |
level = st.number_input("Level", min_value=200, max_value=400, step=1) | |
course_units = st.number_input("Course Units", min_value=1, max_value=4, step=1) | |
with col2: | |
attendance = st.slider("Attendance", min_value=1, max_value=10, step=1) | |
mid_semester = st.slider("Mid Semester Score", min_value=1, max_value=20, step=1) | |
assignments = st.slider("Assignments", min_value=1, max_value=10, step=1) | |
# Make prediction | |
if st.button("Predict Exam Score"): | |
# Add total_score to the input data | |
input_data = np.array([[level, course_units, attendance, mid_semester, assignments]]) | |
prediction = make_prediction(rf_model, reloaded_model, input_data) | |
# Calculate total score | |
total_score = attendance + mid_semester + assignments + prediction[0] | |
st.write(f"Predicted Exam Score: {prediction[0]:.2f}") | |
st.write(f"Total Score: {total_score}") | |
# Calculate GPA | |
gpa = calculate_gpa(total_score) | |
st.write(f"Predicted GPA: {gpa}") | |
if __name__ == '__main__': | |
main() |