Spaces:
Sleeping
Sleeping
File size: 3,771 Bytes
3ea8af4 ae3c5d7 3ea8af4 1e2e075 3ea8af4 00ce994 3ea8af4 00ce994 ae3c5d7 00ce994 ae3c5d7 00ce994 ae3c5d7 3ea8af4 d51d681 d94508f 1e2e075 d94508f 1e2e075 d94508f 1e2e075 d94508f 1e2e075 d51d681 1e2e075 d51d681 3ea8af4 e82172a 3ea8af4 ae3c5d7 3ea8af4 d94508f 3ea8af4 ae3c5d7 653fbbc ae3c5d7 d94508f 861f0f9 ae3c5d7 861f0f9 ae3c5d7 00ce994 ae3c5d7 d51d681 1e2e075 d51d681 3ea8af4 1e2e075 3ea8af4 ae3c5d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
import streamlit as st
from tensorflow.keras.models import load_model
import pickle
import numpy as np
import os
import google.generativeai as genai
# Configure the generative AI with the API key
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
# Load the saved models
with open('rf_model.pkl', 'rb') as file:
rf_model = pickle.load(file)
deep_model = load_model('deep_model.h5')
# Define the function to make predictions using the RandomForestRegressor model
def make_rf_prediction(model, input_data):
prediction = model.predict(input_data)
return prediction
# Define the function to make predictions using the deep learning model
def make_deep_prediction(model, input_data):
prediction = model.predict(input_data).flatten()
return prediction
# Define the function to calculate GPA
def calculate_gpa(total_score):
if total_score >= 70:
return 'A (5 points)', total_score
elif total_score >= 60:
return 'B (4 points)', total_score
elif total_score >= 50:
return 'C (3 points)', total_score
elif total_score >= 45:
return 'D (2 points)', total_score
else:
return 'F (0 points)', total_score
# Function to generate grade-based recommendations using Gemini API
def generate_grade_recommendations(grade):
if grade >= 70:
grade_desc = "good grade"
else:
grade_desc = "bad grade"
input_prompt = f"The student has a {grade_desc}. What recommendations do you have for them?"
model = genai.GenerativeModel('gemini-pro')
response = model.generate_content(input_prompt, generation_config=genai.types.GenerationConfig(max_output_tokens=400))
return response.text
# 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."
)
# 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"):
# Create input data
input_data = np.array([[level, course_units, attendance, mid_semester, assignments]])
# Make predictions using both models
rf_prediction = make_rf_prediction(rf_model, input_data)
deep_prediction = make_deep_prediction(deep_model, input_data)
# Combine predictions
combined_prediction = (rf_prediction + deep_prediction) / 2
# Calculate total score
total_score = attendance + mid_semester + assignments + combined_prediction[0]
# Ensure total score does not exceed 100
total_score = min(total_score, 100)
st.write(f"Predicted Exam Score: {combined_prediction[0]:.2f}")
st.write(f"Total Score: {total_score:.2f}")
# Calculate GPA
gpa, numeric_score = calculate_gpa(total_score)
st.write(f"Predicted GPA: {gpa}")
# Generate recommendations based on GPA
recommendations = generate_grade_recommendations(numeric_score)
st.subheader("Recommendations Based on Grade:")
st.write(recommendations)
if __name__ == '__main__':
main()
|