Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
import google.generativeai as genai
|
3 |
from dotenv import load_dotenv
|
4 |
import os
|
|
|
5 |
|
6 |
# Load environment variables
|
7 |
load_dotenv()
|
@@ -10,59 +11,85 @@ load_dotenv()
|
|
10 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
11 |
model = genai.GenerativeModel('gemini-pro')
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def main():
|
14 |
st.title("JEE SOCA Analysis System π")
|
15 |
st.subheader("AI-Powered Skill Assessment for JEE Aspirants")
|
16 |
|
|
|
|
|
|
|
|
|
|
|
17 |
with st.form("student_form"):
|
18 |
st.header("Student Questionnaire")
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
st.subheader("β° Study Habits")
|
28 |
-
study_hours = st.number_input("Daily Study Hours", min_value=0, max_value=16)
|
29 |
-
time_management = st.select_slider("Time Management Skills",
|
30 |
-
options=["Poor", "Average", "Good", "Excellent"])
|
31 |
-
|
32 |
-
# Problem Solving
|
33 |
-
st.subheader("π Problem Solving")
|
34 |
-
problem_approach = st.radio("Preferred Problem Solving Approach",
|
35 |
-
("Conceptual Understanding",
|
36 |
-
"Formula Memorization",
|
37 |
-
"Practice Problems"))
|
38 |
|
39 |
-
#
|
40 |
-
st.subheader("π§ Stress Management")
|
41 |
-
stress_level = st.select_slider("Stress Level",
|
42 |
-
options=["Very Low", "Low", "Moderate", "High", "Very High"])
|
43 |
-
|
44 |
-
# Submission
|
45 |
submitted = st.form_submit_button("Generate SOCA Analysis")
|
46 |
|
47 |
if submitted:
|
48 |
with st.spinner("Analyzing responses..."):
|
49 |
-
# Prepare prompt
|
50 |
-
prompt =
|
51 |
-
|
52 |
-
|
53 |
-
- Physics: {physics_score}/10
|
54 |
-
- Chemistry: {chemistry_score}/10
|
55 |
-
|
56 |
-
Study Habits:
|
57 |
-
- Daily Study Hours: {study_hours}
|
58 |
-
- Time Management: {time_management}
|
59 |
-
|
60 |
-
Problem Solving:
|
61 |
-
- Approach: {problem_approach}
|
62 |
-
|
63 |
-
Stress Management:
|
64 |
-
- Stress Level: {stress_level}
|
65 |
|
|
|
66 |
Provide the analysis in this format:
|
67 |
**Strengths:** [Identify 3 key strengths]
|
68 |
**Opportunities:** [Suggest 3 improvement areas]
|
@@ -71,11 +98,13 @@ def main():
|
|
71 |
"""
|
72 |
|
73 |
# Get Gemini response
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
79 |
|
|
|
80 |
if __name__ == "__main__":
|
81 |
main()
|
|
|
2 |
import google.generativeai as genai
|
3 |
from dotenv import load_dotenv
|
4 |
import os
|
5 |
+
import json
|
6 |
|
7 |
# Load environment variables
|
8 |
load_dotenv()
|
|
|
11 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
12 |
model = genai.GenerativeModel('gemini-pro')
|
13 |
|
14 |
+
# Load questionnaire from JSON
|
15 |
+
def load_questionnaire():
|
16 |
+
with open('assets/questionnaire.json', 'r') as f:
|
17 |
+
return json.load(f)
|
18 |
+
|
19 |
+
# Render questions based on type
|
20 |
+
def render_question(question):
|
21 |
+
question_type = question.get("type")
|
22 |
+
if question_type == "slider":
|
23 |
+
return st.slider(
|
24 |
+
question["question"],
|
25 |
+
min_value=question.get("min", 1),
|
26 |
+
max_value=question.get("max", 10),
|
27 |
+
value=question.get("default", 5)
|
28 |
+
)
|
29 |
+
elif question_type == "select_slider":
|
30 |
+
return st.select_slider(
|
31 |
+
question["question"],
|
32 |
+
options=question["options"],
|
33 |
+
value=question.get("default")
|
34 |
+
)
|
35 |
+
elif question_type == "radio":
|
36 |
+
return st.radio(
|
37 |
+
question["question"],
|
38 |
+
options=question["options"]
|
39 |
+
)
|
40 |
+
elif question_type == "select":
|
41 |
+
return st.selectbox(
|
42 |
+
question["question"],
|
43 |
+
options=question["options"]
|
44 |
+
)
|
45 |
+
elif question_type == "multiselect":
|
46 |
+
return st.multiselect(
|
47 |
+
question["question"],
|
48 |
+
options=question["options"]
|
49 |
+
)
|
50 |
+
elif question_type == "number":
|
51 |
+
return st.number_input(
|
52 |
+
question["question"],
|
53 |
+
min_value=question.get("min", 0),
|
54 |
+
max_value=question.get("max", 24),
|
55 |
+
value=question.get("default", 4)
|
56 |
+
)
|
57 |
+
else:
|
58 |
+
st.warning(f"Unsupported question type: {question_type}")
|
59 |
+
return None
|
60 |
+
|
61 |
+
# Main function
|
62 |
def main():
|
63 |
st.title("JEE SOCA Analysis System π")
|
64 |
st.subheader("AI-Powered Skill Assessment for JEE Aspirants")
|
65 |
|
66 |
+
# Load questionnaire
|
67 |
+
questionnaire = load_questionnaire()
|
68 |
+
|
69 |
+
# Collect responses
|
70 |
+
responses = {}
|
71 |
with st.form("student_form"):
|
72 |
st.header("Student Questionnaire")
|
73 |
|
74 |
+
# Render questions from JSON
|
75 |
+
for section in questionnaire["questionnaire"]:
|
76 |
+
st.subheader(f"π {section['section']}")
|
77 |
+
for question in section["questions"]:
|
78 |
+
response = render_question(question)
|
79 |
+
if response is not None:
|
80 |
+
responses[question["question"]] = response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
+
# Submit button
|
|
|
|
|
|
|
|
|
|
|
83 |
submitted = st.form_submit_button("Generate SOCA Analysis")
|
84 |
|
85 |
if submitted:
|
86 |
with st.spinner("Analyzing responses..."):
|
87 |
+
# Prepare prompt for Gemini
|
88 |
+
prompt = "Analyze this JEE student's profile and create a SOCA analysis:\n\n"
|
89 |
+
for question, response in responses.items():
|
90 |
+
prompt += f"- {question}: {response}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
+
prompt += """
|
93 |
Provide the analysis in this format:
|
94 |
**Strengths:** [Identify 3 key strengths]
|
95 |
**Opportunities:** [Suggest 3 improvement areas]
|
|
|
98 |
"""
|
99 |
|
100 |
# Get Gemini response
|
101 |
+
try:
|
102 |
+
response = model.generate_content(prompt)
|
103 |
+
st.subheader("SOCA Analysis Report")
|
104 |
+
st.markdown(response.text)
|
105 |
+
except Exception as e:
|
106 |
+
st.error(f"An error occurred while generating the analysis: {e}")
|
107 |
|
108 |
+
# Run the app
|
109 |
if __name__ == "__main__":
|
110 |
main()
|