Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -119,10 +119,106 @@ from groq import Groq
|
|
119 |
app = FastAPI()
|
120 |
handler = Mangum(app)
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
# Pydantic model for request
|
123 |
class ScoreInput(BaseModel):
|
124 |
score_percentages: Dict[str, float]
|
125 |
time_percentages: Dict[str, float]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
# Helper functions
|
128 |
def get_final_score(score_percentages: Dict[str, float], time_percentages: Dict[str, float]) -> Dict[str, float]:
|
@@ -157,12 +253,32 @@ async def analyze_scores(input_data: ScoreInput):
|
|
157 |
final_score = get_final_score(input_data.score_percentages, input_data.time_percentages)
|
158 |
strengths, opportunities, challenges = get_strengths_and_weaknesses(final_score)
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
# Groq API call
|
161 |
api_key2 = os.getenv("GROQ_API_KEY")
|
162 |
if not api_key:
|
163 |
raise HTTPException(status_code=500, detail="Groq API key not found")
|
164 |
|
165 |
client2 = Groq(api_key=api_key2)
|
|
|
166 |
sys_prompt = f"""You are an advanced language model trained to analyze student responses from a questionnaire on Academic, Cognitive, and Study Profile aspects related to JEE Mains preparation. Your task is to generate a personalized SCO (Strengths, Challenges, Opportunities) analysis and an Action Plan section based on the user's inputs.
|
167 |
You have been provided with the strengths {strengths}, Opportunities {opportunities} and Challenges {challenges} skills of the user
|
168 |
Output Structure:
|
@@ -196,21 +312,86 @@ async def analyze_scores(input_data: ScoreInput):
|
|
196 |
7) Bold text where you are taking chapter names from Physics , Chemsitry and Maths only which are in syllabus of Joint Entrance Examination.
|
197 |
8) Dont use "+" or any other special symbol whenever you want to break a line use "\n" to do it in the output.
|
198 |
"""
|
199 |
-
|
200 |
|
201 |
try:
|
202 |
-
|
203 |
messages=[
|
204 |
{"role": "system", "content": sys_prompt},
|
205 |
{"role": "user", "content": f"Generate the SOCA analysis based on the system prompt and {strengths}, {opportunities} and {challenges}. MAKE SURE WE STRICTLY FOLLOW THE STRUCTURE."},
|
206 |
],
|
207 |
model="llama3-70b-8192",
|
208 |
)
|
209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
except Exception as e:
|
211 |
raise HTTPException(status_code=500, detail=f"Error calling Groq API: {str(e)}")
|
212 |
|
213 |
-
return {"analysis":
|
214 |
|
215 |
if __name__ == "__main__":
|
216 |
import uvicorn
|
|
|
119 |
app = FastAPI()
|
120 |
handler = Mangum(app)
|
121 |
|
122 |
+
#SOCA V1 CODE START
|
123 |
+
|
124 |
+
api_key1 = os.getenv('GROQ_API_KEY')
|
125 |
+
|
126 |
+
config = {
|
127 |
+
'llm': {
|
128 |
+
'provider': 'groq',
|
129 |
+
'config': {
|
130 |
+
'model':'llama3-70b-8192',
|
131 |
+
'top_p': 0.5,
|
132 |
+
'api_key': api_key,
|
133 |
+
'stream': True
|
134 |
+
}
|
135 |
+
},
|
136 |
+
'embedder': {
|
137 |
+
'provider': 'huggingface',
|
138 |
+
'config': {
|
139 |
+
'model': 'sentence-transformers/all-mpnet-base-v2'
|
140 |
+
}
|
141 |
+
}
|
142 |
+
}
|
143 |
+
|
144 |
+
swot_bot = App.from_config(config=config)
|
145 |
+
|
146 |
+
swot_bot.add("web_page","https://www.allen.ac.in/engineering/jee-main/tips-tricks/")
|
147 |
+
# swot_bot.add("https://motion.ac.in/blog/jee-main-weightage-chapter-wise/")
|
148 |
+
swot_bot.add("https://www.allen.ac.in/engineering/jee-main/preparation-strategy/")
|
149 |
+
#swot_bot.add("https://byjus.com/jee/how-to-prepare-for-jee-at-home/")
|
150 |
+
swot_bot.add("https://www.askiitians.com/iit-jee/how-to-prepare-for-iit-jee-from-class-11.html")
|
151 |
+
# swot_bot.add("https://byjus.com/jee/complete-study-plan-to-crack-jee-main/")
|
152 |
+
#swot_bot.add("https://mystudycart.com/iit-jee-preparation")
|
153 |
+
swot_bot.add("https://engineering.careers360.com/articles/how-prepare-for-jee-main")
|
154 |
+
|
155 |
+
swot_bot.add("https://www.allenoverseas.com/blog/jee-main-2024-exam-strategies-subject-wise-preparation-tips/")
|
156 |
+
swot_bot.add("https://www.vedantu.com/jee-main/topics")
|
157 |
+
swot_bot.add("https://www.pw.live/exams/wp-content/uploads/2024/01/syllabus-for-jee-main-2024-as-on-01-november-2023-1-3.pdf")
|
158 |
+
swot_bot.add("https://www.pw.live/exams/wp-content/uploads/2024/01/syllabus-for-jee-main-2024-as-on-01-november-2023-4-8.pdf")
|
159 |
+
swot_bot.add("https://www.pw.live/exams/jee/jee-main-chemistry-syllabus/")
|
160 |
+
|
161 |
+
swot_bot.add("https://www.pw.live/topics-chemistry-class-11")
|
162 |
+
swot_bot.add("https://www.pw.live/topics-chemistry-class-12")
|
163 |
+
|
164 |
+
|
165 |
+
system_prompt = """You are an advanced language model trained to analyze student responses from a questionnaire on Academic, Cognitive, and Study Profile aspects related to JEE Mains preparation. Your task is to generate a personalized SCO (Strengths, Challenges, Opportunities) analysis and an Action Plan section based on the user's inputs.
|
166 |
+
Questionnaire Structure:
|
167 |
+
Academic Profile:
|
168 |
+
- Confidence scores in various subjects/topics and subtopics covered in JEE Mains (e.g., Physical Chemistry: Electrochemistry, Redox Reactions; Inorganic Chemistry: Transition Elements, Periodic Table, Representative Elements)
|
169 |
+
Cognitive Profile:
|
170 |
+
- Learning styles (visual, auditory, kinesthetic)
|
171 |
+
- Problem-solving abilities
|
172 |
+
- Time management skills
|
173 |
+
- Attention span and focus
|
174 |
+
Study Profile:
|
175 |
+
- Study habits (consistent/irregular, self-study/coaching)
|
176 |
+
- Average study hours per day
|
177 |
+
- Revision strategies
|
178 |
+
- Test-taking strategies
|
179 |
+
Given: You have been provided with the weightages of different topics/subjects in the JEE Mains exam and common knowledge specific to the JEE context. Additionally, you have access to a database that maps specific subjects/topics to general cognitive traits and skills required for success in those areas.
|
180 |
+
Output Structure:
|
181 |
+
SCO Analysis:
|
182 |
+
Strengths:
|
183 |
+
- List the student's strengths based on their high confidence scores, favorable cognitive abilities, and effective study habits.
|
184 |
+
- Identify general cognitive traits and skills the student excels at based on their performance in specific subjects/topics and subtopics (e.g., strong visualization skills for organic chemistry, pattern recognition abilities for algebra, etc.)
|
185 |
+
- Highlight overarching trends in the student's strengths across related subjects/topics (e.g., strong in Physical Chemistry but struggles in Inorganic Chemistry)
|
186 |
+
Challenges:
|
187 |
+
- Identify the areas where the student faces difficulties based on low confidence scores, cognitive limitations, and ineffective study habits.
|
188 |
+
- Highlight general cognitive traits and skills the student struggles with based on their performance in specific subjects/topics and subtopics.
|
189 |
+
- Identify overarching trends in the student's weaknesses across related subjects/topics.
|
190 |
+
Opportunities:
|
191 |
+
- Suggest opportunities for improvement by leveraging the student's strengths and addressing their challenges.
|
192 |
+
- Recommend ways to enhance the general cognitive traits and skills required for success in specific subjects/topics and subtopics.
|
193 |
+
Action Plan:
|
194 |
+
- Provide a detailed, subject/topic/subtopic-specific action plan tailored to the student's SCO analysis.
|
195 |
+
- Recommend targeted strategies, resources, and techniques to improve their preparation in the identified areas of weakness, including subject-specific cognitive skills and study behaviors.
|
196 |
+
- Suggest ways to enhance their strengths and capitalize on opportunities, including leveraging their strong cognitive traits and effective study habits.
|
197 |
+
- Incorporate time management, revision, and test-taking strategies specific to JEE Mains and the identified subjects/topics/subtopics.
|
198 |
+
- Address overarching trends in the student's strengths and weaknesses across related subjects/topics, and categorize this insight under appropriate headings.
|
199 |
+
|
|
200 |
+
Your analysis and action plan should be comprehensive, consistent, and tailored to the individual student's responses while leveraging your knowledge of the JEE Mains exam context, the mapping of subjects/topics to general cognitive traits and skills, and the ability to identify overarching trends across related subjects/topics."""
|
201 |
+
|
202 |
+
#SOCA v1 CODE END
|
203 |
+
|
204 |
+
|
205 |
+
|
206 |
# Pydantic model for request
|
207 |
class ScoreInput(BaseModel):
|
208 |
score_percentages: Dict[str, float]
|
209 |
time_percentages: Dict[str, float]
|
210 |
+
#SOCA v1 Inputs
|
211 |
+
confidence_scores_str: str
|
212 |
+
problem_solving_approach: str
|
213 |
+
thorough_understanding: str
|
214 |
+
feedback: str
|
215 |
+
misconception: str
|
216 |
+
time_management: str
|
217 |
+
time_division: str
|
218 |
+
mock_test_frequency: str
|
219 |
+
progress_monitoring: str
|
220 |
+
study_methods: str
|
221 |
+
study_techniques: str
|
222 |
|
223 |
# Helper functions
|
224 |
def get_final_score(score_percentages: Dict[str, float], time_percentages: Dict[str, float]) -> Dict[str, float]:
|
|
|
253 |
final_score = get_final_score(input_data.score_percentages, input_data.time_percentages)
|
254 |
strengths, opportunities, challenges = get_strengths_and_weaknesses(final_score)
|
255 |
|
256 |
+
|
257 |
+
|
258 |
+
#SOCA v1 Code Output
|
259 |
+
user_response = f"""Confidence score of the student across different subjects out of 10 :{getattr(user_prompt, 'confidence_scores_str')},
|
260 |
+
'When faced with complex,multi-stemp problems in JEE, how likely are you to approach problem-solving systematically, breaking down each step ?':{getattr(user_prompt, 'problem_solving_approach')},
|
261 |
+
'In your JEE preparation, how likely are you to ensure thorough understanding of fundamental concepts before moving on to advanced topics ?':{getattr(user_prompt, 'thorough_understanding')},
|
262 |
+
'How likely are to integrate feedback from practice tests or teachers into your JEE preparation strategy ?':{getattr(user_prompt, 'feedback')},
|
263 |
+
'When encountering a misconception or misunderstanding in a JEE concept, how likely are you to identify and resolve it ?': {getattr(user_prompt, 'misconception')},
|
264 |
+
'How likely are you to effectively manage time during JEE exams, especially in sections with limited time constraints?':{getattr(user_prompt, 'time_management')},
|
265 |
+
'How do you divide your study time among Physics, Chemistry and Mathematics for JEE ? (Allocate Percentage)': {getattr(user_prompt, 'time_division')},
|
266 |
+
'How often do you use mock tests and past question papers for JEE preparation ?': {getattr(user_prompt, 'mock_test_frequency')},
|
267 |
+
'How do you monitor your progress in JEE topics or chapters?': {getattr(user_prompt, 'progress_monitoring')},
|
268 |
+
'How do you adjust your study methods for difficult or new JEE topics ?': {getattr(user_prompt, 'study_methods')},
|
269 |
+
'What techniques do you use to remember JEE concepts and formulas for a long time ? eg: Flashcards, Mindmap, etc.': {getattr(user_prompt, 'study_techniques')}"""
|
270 |
+
|
271 |
+
|
272 |
+
outputSOCAv1 = swot_bot.query(system_prompt + user_response)
|
273 |
+
|
274 |
+
|
275 |
# Groq API call
|
276 |
api_key2 = os.getenv("GROQ_API_KEY")
|
277 |
if not api_key:
|
278 |
raise HTTPException(status_code=500, detail="Groq API key not found")
|
279 |
|
280 |
client2 = Groq(api_key=api_key2)
|
281 |
+
client3 = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
282 |
sys_prompt = f"""You are an advanced language model trained to analyze student responses from a questionnaire on Academic, Cognitive, and Study Profile aspects related to JEE Mains preparation. Your task is to generate a personalized SCO (Strengths, Challenges, Opportunities) analysis and an Action Plan section based on the user's inputs.
|
283 |
You have been provided with the strengths {strengths}, Opportunities {opportunities} and Challenges {challenges} skills of the user
|
284 |
Output Structure:
|
|
|
312 |
7) Bold text where you are taking chapter names from Physics , Chemsitry and Maths only which are in syllabus of Joint Entrance Examination.
|
313 |
8) Dont use "+" or any other special symbol whenever you want to break a line use "\n" to do it in the output.
|
314 |
"""
|
315 |
+
|
316 |
|
317 |
try:
|
318 |
+
chat_completion2 = client2.chat.completions.create(
|
319 |
messages=[
|
320 |
{"role": "system", "content": sys_prompt},
|
321 |
{"role": "user", "content": f"Generate the SOCA analysis based on the system prompt and {strengths}, {opportunities} and {challenges}. MAKE SURE WE STRICTLY FOLLOW THE STRUCTURE."},
|
322 |
],
|
323 |
model="llama3-70b-8192",
|
324 |
)
|
325 |
+
outputSOCAv2= chat_completion2.choices[0].message.content
|
326 |
+
except Exception as e:
|
327 |
+
raise HTTPException(status_code=500, detail=f"Error calling Groq API: {str(e)}")
|
328 |
+
system_promptMerge = f""" ROLE 1 : You are an advanced language model trained to analyze student responses from a questionnaire on Academic, Cognitive, and Study Profile aspects related to JEE Mains preparation. Your task is to generate a personalized SCO (Strengths, Challenges, Opportunities) analysis and an Action Plan section based on the user's inputs.
|
329 |
+
Questionnaire Structure:
|
330 |
+
Academic Profile:
|
331 |
+
- Confidence scores in various subjects/topics and subtopics covered in JEE Mains (e.g., Physical Chemistry: Electrochemistry, Redox Reactions; Inorganic Chemistry: Transition Elements, Periodic Table, Representative Elements)
|
332 |
+
Cognitive Profile:
|
333 |
+
- Learning styles (visual, auditory, kinesthetic)
|
334 |
+
- Problem-solving abilities
|
335 |
+
- Time management skills
|
336 |
+
- Attention span and focus
|
337 |
+
Study Profile:
|
338 |
+
- Study habits (consistent/irregular, self-study/coaching)
|
339 |
+
- Average study hours per day
|
340 |
+
- Revision strategies
|
341 |
+
- Test-taking strategies
|
342 |
+
Given: You have been provided with the weightages of different topics/subjects in the JEE Mains exam and common knowledge specific to the JEE context. Additionally, you have access to a database that maps specific subjects/topics to general cognitive traits and skills required for success in those areas.
|
343 |
+
The Analysis of Role 1 is given is {outputSOCAv1}.
|
344 |
+
|
345 |
+
ROLE 2 : You are an advanced language model trained to analyze student responses from a questionnaire on Academic, Cognitive, and Study Profile aspects related to JEE Mains preparation. Your task is to generate a personalized SCO (Strengths, Challenges, Opportunities) analysis and an Action Plan section based on the user's inputs.
|
346 |
+
You have been provided with the strengths {strengths}, Opportunities {opportunities} and Challenges {challenges} skills of the user
|
347 |
+
The Analysis of Role 2 is {outputSOCAv2}
|
348 |
+
|
349 |
+
Now you have to merge both the outputs of Role 1 and Role 2 and validate them also with each other .
|
350 |
+
You are an Expert Joint Entrance Examination teacher who has to generate the Strengths , Oppourtunities , Challenges and Action Plan of a user.
|
351 |
+
"""
|
352 |
+
|
353 |
+
OutputStructure="""SCO Analysis:
|
354 |
+
Strengths:
|
355 |
+
- List the student's strengths based on their strengths skills
|
356 |
+
- Let the student now how they can use these strengths in their JEE preparation and exam to improve their score.
|
357 |
+
- Also tell them how do they improve their score more.
|
358 |
+
Opportunities:
|
359 |
+
- List the student's strengths based on their opportunities skills
|
360 |
+
- Suggest opportunities for improvement by leveraging the student's strengths and addressing their challenges.
|
361 |
+
- Recommend ways to enhance their score in the opportunities skills.
|
362 |
+
- Also tell them if they improve in these skills what opportunities they have in improving their scores
|
363 |
+
Challenges:
|
364 |
+
- List the student's strengths based on their challenges skills
|
365 |
+
- Guide the student that these skills are basically the core area where they are lacking
|
366 |
+
- Tell them that if they continue not focusing upon them they might get far away from their JEE goal.
|
367 |
+
Action Plan:
|
368 |
+
- Provide a detailed plan to the student to improve in the challenges skills.
|
369 |
+
- Recommend targeted strategies, resources, and techniques to improve their challenges skills.
|
370 |
+
- Let them know if they improve these areas how it can help boost their scores and make their preparation more effective.
|
371 |
+
- Incorporate time management, revision, and test-taking strategies specific to JEE Mains and the identified subjects/topics/subtopics.
|
372 |
+
|
373 |
+
Things that LLM need to make sure:
|
374 |
+
1) Your analysis and action plan should be comprehensive, consistent, and tailored to the individual student's responses while leveraging your knowledge of the JEE Mains exam context, the mapping of subjects/topics to general cognitive traits and skills, and the ability to identify overarching trends across related subjects/topics.
|
375 |
+
2) Make sure you give the output that extracts the student.
|
376 |
+
3) Make sure you give out output in bullet points.
|
377 |
+
4) While entering a new line in the output use "\n" new line character.
|
378 |
+
5) Make the output very much JEE (Joint Entrance Examination) based and give everything with context to Physics , Chemistry and Maths JEE syllabus.
|
379 |
+
6) Use Italics, Bold and underline appropriately to improve the output more.
|
380 |
+
7) Bold text where you are taking chapter names from Physics , Chemsitry and Maths only which are in syllabus of Joint Entrance Examination.
|
381 |
+
8) Dont use "+" or any other special symbol whenever you want to break a line use "\n" to do it in the output."""
|
382 |
+
try:
|
383 |
+
chat_completion3 = client3.chat.completions.create(
|
384 |
+
messages=[
|
385 |
+
{"role": "system", "content": sys_promptMerge+OutputStructure},
|
386 |
+
{"role": "user", "content": f"Generate the SOCA analysis based on the system prompt and {OutputStructure}"},
|
387 |
+
],
|
388 |
+
model="llama3-70b-8192",
|
389 |
+
)
|
390 |
+
outputSOCAv3= chat_completion3.choices[0].message.content
|
391 |
except Exception as e:
|
392 |
raise HTTPException(status_code=500, detail=f"Error calling Groq API: {str(e)}")
|
393 |
|
394 |
+
return {"analysis": outputSOCAv3}
|
395 |
|
396 |
if __name__ == "__main__":
|
397 |
import uvicorn
|