EAV123 commited on
Commit
1e2e075
·
verified ·
1 Parent(s): e82172a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -6
app.py CHANGED
@@ -2,6 +2,11 @@ import streamlit as st
2
  from tensorflow.keras.models import load_model
3
  import pickle
4
  import numpy as np
 
 
 
 
 
5
 
6
  # Load the saved models
7
  with open('rf_model.pkl', 'rb') as file:
@@ -22,15 +27,27 @@ def make_deep_prediction(model, input_data):
22
  # Define the function to calculate GPA
23
  def calculate_gpa(total_score):
24
  if total_score >= 70:
25
- return 'A (5 points)'
26
  elif total_score >= 60:
27
- return 'B (4 points)'
28
  elif total_score >= 50:
29
- return 'C (3 points)'
30
  elif total_score >= 45:
31
- return 'D (2 points)'
 
 
 
 
 
 
 
32
  else:
33
- return 'F (0 points)'
 
 
 
 
 
34
 
35
  # Create the Streamlit app
36
  def main():
@@ -75,8 +92,13 @@ def main():
75
  st.write(f"Total Score: {total_score:.2f}")
76
 
77
  # Calculate GPA
78
- gpa = calculate_gpa(total_score)
79
  st.write(f"Predicted GPA: {gpa}")
80
 
 
 
 
 
 
81
  if __name__ == '__main__':
82
  main()
 
2
  from tensorflow.keras.models import load_model
3
  import pickle
4
  import numpy as np
5
+ import os
6
+ import google.generativeai as genai
7
+
8
+ # Configure the generative AI with the API key
9
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
10
 
11
  # Load the saved models
12
  with open('rf_model.pkl', 'rb') as file:
 
27
  # Define the function to calculate GPA
28
  def calculate_gpa(total_score):
29
  if total_score >= 70:
30
+ return 'A (5 points)', total_score
31
  elif total_score >= 60:
32
+ return 'B (4 points)', total_score
33
  elif total_score >= 50:
34
+ return 'C (3 points)', total_score
35
  elif total_score >= 45:
36
+ return 'D (2 points)', total_score
37
+ else:
38
+ return 'F (0 points)', total_score
39
+
40
+ # Function to generate grade-based recommendations using Gemini API
41
+ def generate_grade_recommendations(grade):
42
+ if grade >= 70:
43
+ grade_desc = "good grade"
44
  else:
45
+ grade_desc = "bad grade"
46
+
47
+ input_prompt = f"The student has a {grade_desc}. What recommendations do you have for them?"
48
+ model = genai.GenerativeModel('gemini-pro')
49
+ response = model.generate_content(input_prompt, generation_config=genai.types.GenerationConfig(max_output_tokens=400))
50
+ return response.text
51
 
52
  # Create the Streamlit app
53
  def main():
 
92
  st.write(f"Total Score: {total_score:.2f}")
93
 
94
  # Calculate GPA
95
+ gpa, numeric_score = calculate_gpa(total_score)
96
  st.write(f"Predicted GPA: {gpa}")
97
 
98
+ # Generate recommendations based on GPA
99
+ recommendations = generate_grade_recommendations(numeric_score)
100
+ st.subheader("Recommendations Based on Grade:")
101
+ st.write(recommendations)
102
+
103
  if __name__ == '__main__':
104
  main()