Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile +45 -0
- main.py +397 -0
- requirements.txt +9 -0
Dockerfile
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# # you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
# FROM python:3.9
|
| 5 |
+
|
| 6 |
+
# WORKDIR /code
|
| 7 |
+
|
| 8 |
+
# COPY ./requirements.txt /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
# RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 11 |
+
|
| 12 |
+
# COPY . .
|
| 13 |
+
|
| 14 |
+
# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
| 15 |
+
|
| 16 |
+
FROM python:3.12
|
| 17 |
+
### Set up user with permissions
|
| 18 |
+
# Set up a new user named "user" with user ID 1000
|
| 19 |
+
RUN useradd -m -u 1000 user
|
| 20 |
+
|
| 21 |
+
# Switch to the "user" user
|
| 22 |
+
USER user
|
| 23 |
+
|
| 24 |
+
# Set home to the user's home directory
|
| 25 |
+
ENV HOME=/home/user \
|
| 26 |
+
PATH=/home/user/.local/bin:$PATH
|
| 27 |
+
|
| 28 |
+
# Set the working directory to the user's home directory
|
| 29 |
+
WORKDIR $HOME/app
|
| 30 |
+
|
| 31 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
| 32 |
+
COPY --chown=user . $HOME/app
|
| 33 |
+
|
| 34 |
+
### Set up app-specific content
|
| 35 |
+
COPY requirements.txt requirements.txt
|
| 36 |
+
RUN pip3 install -r requirements.txt
|
| 37 |
+
|
| 38 |
+
COPY . .
|
| 39 |
+
|
| 40 |
+
### Update permissions for the app
|
| 41 |
+
USER root
|
| 42 |
+
RUN chmod 777 ~/app/*
|
| 43 |
+
USER user
|
| 44 |
+
|
| 45 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# # main.py
|
| 2 |
+
# from fastapi import FastAPI, HTTPException
|
| 3 |
+
# from pydantic import BaseModel
|
| 4 |
+
# from typing import Dict
|
| 5 |
+
# import os
|
| 6 |
+
# from groq import Groq
|
| 7 |
+
|
| 8 |
+
# app = FastAPI()
|
| 9 |
+
|
| 10 |
+
# # Pydantic model for request
|
| 11 |
+
# class ScoreInput(BaseModel):
|
| 12 |
+
# score_percentages: Dict[str, float]
|
| 13 |
+
# time_percentages: Dict[str, float]
|
| 14 |
+
|
| 15 |
+
# # Helper functions
|
| 16 |
+
# def get_final_score(score_percentages: Dict[str, float], time_percentages: Dict[str, float]) -> Dict[str, float]:
|
| 17 |
+
# final_score = {}
|
| 18 |
+
# for skill in score_percentages:
|
| 19 |
+
# score_avg = (score_percentages[skill] + time_percentages[skill]) / 2
|
| 20 |
+
# final_score[skill] = score_avg
|
| 21 |
+
# return final_score
|
| 22 |
+
|
| 23 |
+
# def get_strengths_and_weaknesses(final_score: Dict[str, float]):
|
| 24 |
+
# sorted_skills = sorted(
|
| 25 |
+
# [(skill, score) for skill, score in final_score.items()],
|
| 26 |
+
# key=lambda item: item[1],
|
| 27 |
+
# reverse=True
|
| 28 |
+
# )
|
| 29 |
+
# num_skills = len(sorted_skills)
|
| 30 |
+
# if num_skills == 0:
|
| 31 |
+
# return [], [], []
|
| 32 |
+
|
| 33 |
+
# split1 = num_skills // 3
|
| 34 |
+
# split2 = 2 * (num_skills // 3)
|
| 35 |
+
|
| 36 |
+
# strengths = sorted_skills[:split1]
|
| 37 |
+
# opportunities = sorted_skills[split1:split2]
|
| 38 |
+
# challenges = sorted_skills[split2:]
|
| 39 |
+
|
| 40 |
+
# return strengths, opportunities, challenges
|
| 41 |
+
|
| 42 |
+
# # FastAPI route
|
| 43 |
+
# @app.post("/analyze")
|
| 44 |
+
# async def analyze_scores(input_data: ScoreInput):
|
| 45 |
+
# final_score = get_final_score(input_data.score_percentages, input_data.time_percentages)
|
| 46 |
+
# strengths, opportunities, challenges = get_strengths_and_weaknesses(final_score)
|
| 47 |
+
|
| 48 |
+
# # Groq API call
|
| 49 |
+
# api_key = os.getenv("GROQ_API_KEY")
|
| 50 |
+
# if not api_key:
|
| 51 |
+
# raise HTTPException(status_code=500, detail="Groq API key not found")
|
| 52 |
+
|
| 53 |
+
# client = Groq(api_key=api_key)
|
| 54 |
+
# 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.
|
| 55 |
+
# You have been provided with the strengths {strengths}, Opportunities {opportunities} and Challenges {challenges} skills of the user
|
| 56 |
+
# Output Structure:
|
| 57 |
+
# SCO Analysis:
|
| 58 |
+
# Strengths:
|
| 59 |
+
# - List the student's strengths based on their {strengths} skills
|
| 60 |
+
# - Let the student now how they can use these strengths in their JEE preparation and exam to improve their score.
|
| 61 |
+
# - Also tell them how do they improve their score more.
|
| 62 |
+
# Opportunities:
|
| 63 |
+
# - List the student's strengths based on their {opportunities} skills
|
| 64 |
+
# - Suggest opportunities for improvement by leveraging the student's strengths and addressing their challenges.
|
| 65 |
+
# - Recommend ways to enhance their score in the {opportunities} skills.
|
| 66 |
+
# - Also tell them if they improve in these skills what opportunities they have in improving their scores
|
| 67 |
+
# Challenges:
|
| 68 |
+
# - List the student's strengths based on their {challenges} skills
|
| 69 |
+
# - Guide the student that these skills are basically the core area where they are lacking
|
| 70 |
+
# - Tell them that if they continue not focusing upon them they might get far away from their JEE goal.
|
| 71 |
+
# Action Plan:
|
| 72 |
+
# - Provide a detailed plan to the student to improve in the {challenges} skills.
|
| 73 |
+
# - Recommend targeted strategies, resources, and techniques to improve their {challenges} skills.
|
| 74 |
+
# - Let them know if they improve these areas how it can help boost their scores and make their preparation more effective.
|
| 75 |
+
# - Incorporate time management, revision, and test-taking strategies specific to JEE Mains and the identified subjects/topics/subtopics.
|
| 76 |
+
|
| 77 |
+
# Things that LLM need to make sure:
|
| 78 |
+
# 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.
|
| 79 |
+
# 2) Make sure you give the output that extracts the student.
|
| 80 |
+
# 3) Make sure you give out output in bullet points.
|
| 81 |
+
# 4) While entering a new line in the output use "\n" new line character.
|
| 82 |
+
# 5) Make the output very much JEE (Joint Entrance Examination) based and give everything with context to Physics , Chemistry and Maths JEE syllabus.
|
| 83 |
+
# 6) Use Italics, Bold and underline appropriately to improve the output more.
|
| 84 |
+
# 7) Bold text where you are taking chapter names from Physics , Chemsitry and Maths only which are in syllabus of Joint Entrance Examination.
|
| 85 |
+
# 8) Dont use "+" or any other special symbol whenever you want to break a line use "\n" to do it in the output.
|
| 86 |
+
# """
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
# try:
|
| 90 |
+
# chat_completion = client.chat.completions.create(
|
| 91 |
+
# messages=[
|
| 92 |
+
# {"role": "system", "content": sys_prompt},
|
| 93 |
+
# {"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."},
|
| 94 |
+
# ],
|
| 95 |
+
# model="llama3-70b-8192",
|
| 96 |
+
# )
|
| 97 |
+
# analysis = chat_completion.choices[0].message.content
|
| 98 |
+
# except Exception as e:
|
| 99 |
+
# raise HTTPException(status_code=500, detail=f"Error calling Groq API: {str(e)}")
|
| 100 |
+
|
| 101 |
+
# return {"analysis": analysis}
|
| 102 |
+
|
| 103 |
+
# if __name__ == "__main__":
|
| 104 |
+
# import uvicorn
|
| 105 |
+
# uvicorn.run(app, host="0.0.0.0", port=8000)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
# Merger of SOCA v1 and SOCA v2
|
| 111 |
+
from embedchain import App
|
| 112 |
+
from fastapi import FastAPI, HTTPException
|
| 113 |
+
from mangum import Mangum
|
| 114 |
+
from pydantic import BaseModel
|
| 115 |
+
from typing import Dict
|
| 116 |
+
import os
|
| 117 |
+
from groq import Groq
|
| 118 |
+
|
| 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_key1,
|
| 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]:
|
| 225 |
+
final_score = {}
|
| 226 |
+
for skill in score_percentages:
|
| 227 |
+
score_avg = (score_percentages[skill] + time_percentages[skill]) / 2
|
| 228 |
+
final_score[skill] = score_avg
|
| 229 |
+
return final_score
|
| 230 |
+
|
| 231 |
+
def get_strengths_and_weaknesses(final_score: Dict[str, float]):
|
| 232 |
+
sorted_skills = sorted(
|
| 233 |
+
[(skill, score) for skill, score in final_score.items()],
|
| 234 |
+
key=lambda item: item[1],
|
| 235 |
+
reverse=True
|
| 236 |
+
)
|
| 237 |
+
num_skills = len(sorted_skills)
|
| 238 |
+
if num_skills == 0:
|
| 239 |
+
return [], [], []
|
| 240 |
+
|
| 241 |
+
split1 = num_skills // 3
|
| 242 |
+
split2 = 2 * (num_skills // 3)
|
| 243 |
+
|
| 244 |
+
strengths = sorted_skills[:split1]
|
| 245 |
+
opportunities = sorted_skills[split1:split2]
|
| 246 |
+
challenges = sorted_skills[split2:]
|
| 247 |
+
|
| 248 |
+
return strengths, opportunities, challenges
|
| 249 |
+
|
| 250 |
+
# FastAPI route
|
| 251 |
+
@app.post("/analyze")
|
| 252 |
+
async def analyze_scores(input_data: ScoreInput):
|
| 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 :{input_data.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 ?':{input_data.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 ?':{input_data.thorough_understanding},
|
| 262 |
+
'How likely are to integrate feedback from practice tests or teachers into your JEE preparation strategy ?':{input_data.feedback},
|
| 263 |
+
'When encountering a misconception or misunderstanding in a JEE concept, how likely are you to identify and resolve it ?': {input_data.misconception},
|
| 264 |
+
'How likely are you to effectively manage time during JEE exams, especially in sections with limited time constraints?':{input_data.time_management},
|
| 265 |
+
'How do you divide your study time among Physics, Chemistry and Mathematics for JEE ? (Allocate Percentage)': {input_data.time_division},
|
| 266 |
+
'How often do you use mock tests and past question papers for JEE preparation ?': {input_data.mock_test_frequency},
|
| 267 |
+
'How do you monitor your progress in JEE topics or chapters?': {input_data.progress_monitoring},
|
| 268 |
+
'How do you adjust your study methods for difficult or new JEE topics ?': {input_data.study_methods},
|
| 269 |
+
'What techniques do you use to remember JEE concepts and formulas for a long time ? eg: Flashcards, Mindmap, etc.': {input_data.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_key2:
|
| 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:
|
| 285 |
+
SCO Analysis:
|
| 286 |
+
Strengths:
|
| 287 |
+
- List the student's strengths based on their {strengths} skills
|
| 288 |
+
- Let the student now how they can use these strengths in their JEE preparation and exam to improve their score.
|
| 289 |
+
- Also tell them how do they improve their score more.
|
| 290 |
+
Opportunities:
|
| 291 |
+
- List the student's strengths based on their {opportunities} skills
|
| 292 |
+
- Suggest opportunities for improvement by leveraging the student's strengths and addressing their challenges.
|
| 293 |
+
- Recommend ways to enhance their score in the {opportunities} skills.
|
| 294 |
+
- Also tell them if they improve in these skills what opportunities they have in improving their scores
|
| 295 |
+
Challenges:
|
| 296 |
+
- List the student's strengths based on their {challenges} skills
|
| 297 |
+
- Guide the student that these skills are basically the core area where they are lacking
|
| 298 |
+
- Tell them that if they continue not focusing upon them they might get far away from their JEE goal.
|
| 299 |
+
Action Plan:
|
| 300 |
+
- Provide a detailed plan to the student to improve in the {challenges} skills.
|
| 301 |
+
- Recommend targeted strategies, resources, and techniques to improve their {challenges} skills.
|
| 302 |
+
- Let them know if they improve these areas how it can help boost their scores and make their preparation more effective.
|
| 303 |
+
- Incorporate time management, revision, and test-taking strategies specific to JEE Mains and the identified subjects/topics/subtopics.
|
| 304 |
+
|
| 305 |
+
Things that LLM need to make sure:
|
| 306 |
+
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.
|
| 307 |
+
2) Make sure you give the output that extracts the student.
|
| 308 |
+
3) Make sure you give out output in bullet points.
|
| 309 |
+
4) While entering a new line in the output use "\n" new line character.
|
| 310 |
+
5) Make the output very much JEE (Joint Entrance Examination) based and give everything with context to Physics , Chemistry and Maths JEE syllabus.
|
| 311 |
+
6) Bold text where you are taking chapter names from Physics , Chemsitry and Maths only which are in syllabus of Joint Entrance Examination.
|
| 312 |
+
7) Dont use "+" or any other special symbol whenever you want to break a line use "\n" to do it in the output.
|
| 313 |
+
"""
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
try:
|
| 317 |
+
chat_completion2 = client2.chat.completions.create(
|
| 318 |
+
messages=[
|
| 319 |
+
{"role": "system", "content": sys_prompt},
|
| 320 |
+
{"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."},
|
| 321 |
+
],
|
| 322 |
+
model="llama3-70b-8192",
|
| 323 |
+
)
|
| 324 |
+
except Exception as e:
|
| 325 |
+
raise HTTPException(status_code=500, detail=f"Error calling Groq API: {str(e)}")
|
| 326 |
+
outputSOCAv2= chat_completion2.choices[0].message.content
|
| 327 |
+
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.
|
| 328 |
+
Questionnaire Structure:
|
| 329 |
+
Academic Profile:
|
| 330 |
+
- 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)
|
| 331 |
+
Cognitive Profile:
|
| 332 |
+
- Learning styles (visual, auditory, kinesthetic)
|
| 333 |
+
- Problem-solving abilities
|
| 334 |
+
- Time management skills
|
| 335 |
+
- Attention span and focus
|
| 336 |
+
Study Profile:
|
| 337 |
+
- Study habits (consistent/irregular, self-study/coaching)
|
| 338 |
+
- Average study hours per day
|
| 339 |
+
- Revision strategies
|
| 340 |
+
- Test-taking strategies
|
| 341 |
+
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.
|
| 342 |
+
The Analysis of Role 1 is given is {outputSOCAv1}.
|
| 343 |
+
|
| 344 |
+
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.
|
| 345 |
+
You have been provided with the strengths {strengths}, Opportunities {opportunities} and Challenges {challenges} skills of the user
|
| 346 |
+
The Analysis of Role 2 is {outputSOCAv2}
|
| 347 |
+
|
| 348 |
+
Now you have to merge both the outputs of Role 1 and Role 2 and validate them also with each other .
|
| 349 |
+
You are an Expert Joint Entrance Examination teacher who has to generate the Strengths , Oppourtunities , Challenges and Action Plan of a user.
|
| 350 |
+
"""
|
| 351 |
+
|
| 352 |
+
OutputStructure="""SCO Analysis:
|
| 353 |
+
Strengths:
|
| 354 |
+
- List the student's strengths based on their strengths skills
|
| 355 |
+
- Let the student now how they can use these strengths in their JEE preparation and exam to improve their score.
|
| 356 |
+
- Also tell them how do they improve their score more.
|
| 357 |
+
Opportunities:
|
| 358 |
+
- List the student's strengths based on their opportunities skills
|
| 359 |
+
- Suggest opportunities for improvement by leveraging the student's strengths and addressing their challenges.
|
| 360 |
+
- Recommend ways to enhance their score in the opportunities skills.
|
| 361 |
+
- Also tell them if they improve in these skills what opportunities they have in improving their scores
|
| 362 |
+
Challenges:
|
| 363 |
+
- List the student's strengths based on their challenges skills
|
| 364 |
+
- Guide the student that these skills are basically the core area where they are lacking
|
| 365 |
+
- Tell them that if they continue not focusing upon them they might get far away from their JEE goal.
|
| 366 |
+
Action Plan:
|
| 367 |
+
- Provide a detailed plan to the student to improve in the challenges skills.
|
| 368 |
+
- Recommend targeted strategies, resources, and techniques to improve their challenges skills.
|
| 369 |
+
- Let them know if they improve these areas how it can help boost their scores and make their preparation more effective.
|
| 370 |
+
- Incorporate time management, revision, and test-taking strategies specific to JEE Mains and the identified subjects/topics/subtopics.
|
| 371 |
+
|
| 372 |
+
Things that LLM need to make sure:
|
| 373 |
+
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.
|
| 374 |
+
2) Make sure you give the output that extracts the student.
|
| 375 |
+
3) Make sure you give out output in bullet points.
|
| 376 |
+
4) While entering a new line in the output use "\n" new line character.
|
| 377 |
+
5) Make the output very much JEE (Joint Entrance Examination) based and give everything with context to Physics , Chemistry and Maths JEE syllabus.
|
| 378 |
+
6) Use Italics, Bold and underline appropriately to improve the output more.
|
| 379 |
+
7) Bold text where you are taking chapter names from Physics , Chemsitry and Maths only which are in syllabus of Joint Entrance Examination.
|
| 380 |
+
8) Dont use "+" or any other special symbol whenever you want to break a line use "\n" to do it in the output."""
|
| 381 |
+
try:
|
| 382 |
+
chat_completion3 = client3.chat.completions.create(
|
| 383 |
+
messages=[
|
| 384 |
+
{"role": "system", "content": system_promptMerge+OutputStructure},
|
| 385 |
+
{"role": "user", "content": f"Generate the SOCA analysis based on the system prompt and {OutputStructure}"},
|
| 386 |
+
],
|
| 387 |
+
model="llama3-70b-8192",
|
| 388 |
+
)
|
| 389 |
+
except Exception as e:
|
| 390 |
+
raise HTTPException(status_code=500, detail=f"Error calling Groq API: {str(e)}")
|
| 391 |
+
outputSOCAv3= chat_completion3.choices[0].message.content
|
| 392 |
+
|
| 393 |
+
return {"analysis": outputSOCAv3}
|
| 394 |
+
|
| 395 |
+
if __name__ == "__main__":
|
| 396 |
+
import uvicorn
|
| 397 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
groq
|
| 4 |
+
langchain-groq
|
| 5 |
+
langchain_huggingface
|
| 6 |
+
embedchain
|
| 7 |
+
mangum
|
| 8 |
+
sentence-transformers
|
| 9 |
+
pydantic
|