Spaces:
Sleeping
Sleeping
Commit ·
b71e805
0
Parent(s):
first commit
Browse files- .gitignore +12 -0
- main.py +505 -0
- psychology_report.md +49 -0
- utils.py +30 -0
- vpk_user_answers.json +62 -0
.gitignore
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python cache
|
| 2 |
+
__pycache__/
|
| 3 |
+
|
| 4 |
+
# Virtual Environment
|
| 5 |
+
chatenv/
|
| 6 |
+
|
| 7 |
+
# Chroma DB databases
|
| 8 |
+
chroma_db_*/
|
| 9 |
+
|
| 10 |
+
# Other common Python files to ignore
|
| 11 |
+
.env
|
| 12 |
+
*.pyc
|
main.py
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import json
|
| 2 |
+
# from groq import Groq
|
| 3 |
+
# import os
|
| 4 |
+
# from dotenv import load_dotenv
|
| 5 |
+
# import random
|
| 6 |
+
# from utils import get_random, get_mongo_collection
|
| 7 |
+
|
| 8 |
+
# load_dotenv()
|
| 9 |
+
# some = get_random()
|
| 10 |
+
# GROQ_API_KEY = os.getenv(f"GROQ_API_KEY{some}")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# def count_doshas(user_id):
|
| 15 |
+
# collection = get_mongo_collection()
|
| 16 |
+
# cursor = collection.find({"templateName":"Kapha,Pitta,Vata"},{"userId":user_id}).sort("createdAt", -1).limit(1)
|
| 17 |
+
# mapping = {'1':'Vata','2':'Pitta','3':'Kapha'}
|
| 18 |
+
# counts = {"Vata": 0, "Pitta": 0, "Kapha": 0}
|
| 19 |
+
# for item in cursor:
|
| 20 |
+
# # print(item)
|
| 21 |
+
# for lst in item["answers"]:
|
| 22 |
+
# # print(mapping[lst['answer'][:1]])
|
| 23 |
+
# counts[mapping[lst['answer'][:1]]] += 1
|
| 24 |
+
|
| 25 |
+
# return counts
|
| 26 |
+
|
| 27 |
+
# def assign_personality(counts):
|
| 28 |
+
# v = counts["Vata"]
|
| 29 |
+
# p = counts["Pitta"]
|
| 30 |
+
# k = counts["Kapha"]
|
| 31 |
+
|
| 32 |
+
# # Single dominant dosha
|
| 33 |
+
# if v >= 7: return "Vata"
|
| 34 |
+
# if p >= 7: return "Pitta"
|
| 35 |
+
# if k >= 7: return "Kapha"
|
| 36 |
+
|
| 37 |
+
# # Dual dosha
|
| 38 |
+
# if v >= 5 and p >= 5: return "Vata-Pitta"
|
| 39 |
+
# if p >= 5 and k >= 5: return "Pitta-Kapha"
|
| 40 |
+
# if v >= 5 and k >= 5: return "Vata-Kapha"
|
| 41 |
+
|
| 42 |
+
# # Tridoshic
|
| 43 |
+
# if v >= 3 and p >= 3 and k >= 3: return "Vata-Pitta-Kapha"
|
| 44 |
+
|
| 45 |
+
# return "Unclear"
|
| 46 |
+
|
| 47 |
+
# # -------------------------------------
|
| 48 |
+
# # TRAITS DICTIONARY
|
| 49 |
+
# # -------------------------------------
|
| 50 |
+
|
| 51 |
+
# TRAITS = {
|
| 52 |
+
# "Vata": """
|
| 53 |
+
# Vata
|
| 54 |
+
# Vata types are quick and agile in their minds with often changing
|
| 55 |
+
# interests and inclinations. They are talkative, informed and
|
| 56 |
+
# intellectual and can understand many different points of view their minds easily
|
| 57 |
+
# waver and can wander out of control. While they may have some knowledge of many
|
| 58 |
+
# different subjects, the tend to lack in depth knowledge about one subject specifically.
|
| 59 |
+
|
| 60 |
+
# They ack determinism and self confidence and often have a negative perception of themselves.
|
| 61 |
+
# Vata types suffer most from fear, which is their first reaction to anything new or strange. They like to worry easily get afflicted by anxiety, and usually lack stability. They get saced out and may be absent-minded. Their memory and short-term and erratic. They suffer quickly from overwork and over-exercise and tend to overextend themselves in whatever they do.
|
| 62 |
+
# They are good at creative pursuits. They can be highly sociable and like to mix with people of all types. But, when there is too much vata, they tend to become loners and hypersensitive to contact. This is generally because they have too much to say and do not know how to relate it.
|
| 63 |
+
|
| 64 |
+
# They are the most adaptable to change.
|
| 65 |
+
|
| 66 |
+
# If there is too much vata, there is a lot of instability and agitation in the mind which results in exccesive worrying and makes problems appear larger than they are. They are prone to premature action and inappropriate action.
|
| 67 |
+
|
| 68 |
+
# High vata manifests as fear, alienation, and possible nervous breakdowns. They can also suffer from insomnia, tremors, palpitations and rapid shifts of mood.
|
| 69 |
+
# """,
|
| 70 |
+
|
| 71 |
+
# "Pitta": """
|
| 72 |
+
# Pitta
|
| 73 |
+
# Pitta types are intelligent, perceptive and discriminating. They have sharp minds and are able to see the world in a clear and systematic manner. However, they can also be opinionated, judgmental and self -righteous.
|
| 74 |
+
|
| 75 |
+
# They are prone to anger and tend to be aggressive and domineering. They are not afraid of conflict and can be more aggressive when the situation presents itself. They have probing minds and can be good at research. They also have good debating skills.
|
| 76 |
+
|
| 77 |
+
# They have a hard time seeing someone else’s point of view and may lack compassion. They prefer hierarchy and authority over consensus. They are highly determined people.
|
| 78 |
+
|
| 79 |
+
# They usually have food self-control but they can be self-absorbed and anti-social.
|
| 80 |
+
|
| 81 |
+
# High pitta causes aggressiveness and violence.
|
| 82 |
+
# """,
|
| 83 |
+
|
| 84 |
+
# "Kapha": """
|
| 85 |
+
# Kapha
|
| 86 |
+
# Kaphas are naturally emotional in temperament and have tremendous love, devotion and loyalty. Negatively, they can have great desire, and may be possessive and greedy. They are romantic, sentimental, and cry easily.
|
| 87 |
+
|
| 88 |
+
# They are slower in learning than others but they retain what they learn well. They are better at finishing things than they are at starting something new. They are natural followers and like to work in association or within large teams.
|
| 89 |
+
|
| 90 |
+
# They are stable but can sometimes stagnate. They don’t like change and find it very difficult to change even when they want to. They are friendly to people they know but have difficulty in relating to foreigners.
|
| 91 |
+
|
| 92 |
+
# Kapha types are least likely to express anti-social behavior but they are preoccupied with what others think about them.
|
| 93 |
+
|
| 94 |
+
# High kaha cuses metal dullness and poor perception and they tend to suffer from a lack of motivation.
|
| 95 |
+
|
| 96 |
+
# They tend to want to own and control everything and have a high degree of possessiveness
|
| 97 |
+
|
| 98 |
+
# They are prone to over-sleeping overindulging.
|
| 99 |
+
# """,
|
| 100 |
+
|
| 101 |
+
# "Vata-Pitta": """
|
| 102 |
+
# Vata – Pitta (VP)
|
| 103 |
+
# VP types have the volatility of air and fire combined. Fear and anger mix within them in unpredictable way. If something doesn’t make them fearful, it makes them angry.
|
| 104 |
+
|
| 105 |
+
# They often look for someone who they can unload their negative emotions on.
|
| 106 |
+
|
| 107 |
+
# They find it difficult to withstand criticism.
|
| 108 |
+
|
| 109 |
+
# They are generally highly intelligent and require a lifestyle that can accommodate their volatility.
|
| 110 |
+
|
| 111 |
+
# They will thrive in an environment that supports them and creates a safe space for them to express their volatility.
|
| 112 |
+
# """,
|
| 113 |
+
|
| 114 |
+
# "Pitta-Kapha": """
|
| 115 |
+
# Pitta – Kapha (PK)
|
| 116 |
+
# Pitta kapha types are psychologically strong in general and don’t seek help easily.
|
| 117 |
+
|
| 118 |
+
# They lack flexibility and adaptability.
|
| 119 |
+
|
| 120 |
+
# They prefer to be dominating and controlling.
|
| 121 |
+
|
| 122 |
+
# They tend to be conservative and possessive. This leads them to eventual frustration because they cannot control everything around them.
|
| 123 |
+
|
| 124 |
+
# They require new activities, new challenges, and new ways to show their creativity.
|
| 125 |
+
# """,
|
| 126 |
+
|
| 127 |
+
# "Vata-Kapha": """
|
| 128 |
+
# Vata – Kapha (VK)
|
| 129 |
+
# VK types lack energy, motivation and passion. They sometimes simply do not have the fire to get things started.
|
| 130 |
+
|
| 131 |
+
# They are often hypersensitive, and passive-dependent.
|
| 132 |
+
|
| 133 |
+
# They lack the energy to put plans into action.
|
| 134 |
+
|
| 135 |
+
# They will go out of their way to agree with what you have said.
|
| 136 |
+
|
| 137 |
+
# They have chameleon-style personalities where they can appear to be what people want them to be. They will often also blame themselves for others’ mistakes.
|
| 138 |
+
|
| 139 |
+
# They can be highly adaptable and humble.
|
| 140 |
+
|
| 141 |
+
# They tend to be naïve and need to be more realistic about other people and their motivations.
|
| 142 |
+
# """,
|
| 143 |
+
|
| 144 |
+
# "Vata-Pitta-Kapha": """
|
| 145 |
+
# Vata – Pitta – Kapha (VPK)
|
| 146 |
+
# This is very rare that each of the doshas exist in equal amounts.
|
| 147 |
+
|
| 148 |
+
# Their condition psychologically can be constantly changing and unpredictable.
|
| 149 |
+
|
| 150 |
+
# Their psychological state is often a reflection of their circumstances rather than their personality.
|
| 151 |
+
# """
|
| 152 |
+
# }
|
| 153 |
+
|
| 154 |
+
# def get_traits_for_type(personality_type):
|
| 155 |
+
# return TRAITS.get(personality_type, "No traits found for this type.")
|
| 156 |
+
|
| 157 |
+
# # -------------------------------------
|
| 158 |
+
# # GROQ: GENERATE PSYCHOLOGY REPORT
|
| 159 |
+
# # -------------------------------------
|
| 160 |
+
|
| 161 |
+
# client = Groq(api_key=GROQ_API_KEY)
|
| 162 |
+
# def generate_psychology_report(personality_type, traits_text, dosha_counts):
|
| 163 |
+
# prompt = f"""
|
| 164 |
+
# You are an expert Ayurvedic psychologist.
|
| 165 |
+
|
| 166 |
+
# Write a **deeply personal psychological report directly addressing the person as "you"**.
|
| 167 |
+
# This should NOT sound like an academic explanation — it should feel like an
|
| 168 |
+
# insightful evaluation about them.
|
| 169 |
+
|
| 170 |
+
# ### REQUIRED STYLE:
|
| 171 |
+
# - Address the reader as **"you"** throughout
|
| 172 |
+
# - Tone: warm, empathetic, reflective, personal
|
| 173 |
+
# - Use gentle interpretations (“you often…”, “you tend to…”, “you sometimes struggle…”)
|
| 174 |
+
# - Explore emotional patterns, thought styles, reactions, strengths, blindspots
|
| 175 |
+
|
| 176 |
+
# **Formatting Instructions:**
|
| 177 |
+
# - The output MUST be in **Markdown**.
|
| 178 |
+
# - Use `#` for the Main Title (e.g., # Personality Report Report).
|
| 179 |
+
# - Use `##` for Section Headers (e.g., ## Core Personality).
|
| 180 |
+
# - Use bullet points `- ` for lists.
|
| 181 |
+
# - Use **bold** text for key strengths or warnings.
|
| 182 |
+
# - Do not wrap the output in a code block (like ```markdown). Just return the raw markdown.
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
# ### Input Data
|
| 186 |
+
# Personality Type: **{personality_type}**
|
| 187 |
+
# Dosha Counts: {dosha_counts}
|
| 188 |
+
|
| 189 |
+
# Relevant Ayurvedic Traits:
|
| 190 |
+
# --------------------------
|
| 191 |
+
# {traits_text}
|
| 192 |
+
|
| 193 |
+
# Begin the personal Markdown report now.
|
| 194 |
+
# """
|
| 195 |
+
|
| 196 |
+
# completion = client.chat.completions.create(
|
| 197 |
+
# model="openai/gpt-oss-20b",
|
| 198 |
+
# temperature=1.35,
|
| 199 |
+
# max_tokens=3500,
|
| 200 |
+
# messages=[
|
| 201 |
+
# {"role": "system", "content": "You write personal Ayurvedic psychological reports"},
|
| 202 |
+
# {"role": "user", "content": prompt}
|
| 203 |
+
# ]
|
| 204 |
+
# )
|
| 205 |
+
|
| 206 |
+
# return completion.choices[0].message.content
|
| 207 |
+
|
| 208 |
+
# # -------------------------------------
|
| 209 |
+
# # SAVE MARKDOWN
|
| 210 |
+
# # -------------------------------------
|
| 211 |
+
|
| 212 |
+
# def save_report(markdown_text, filename="psychology_report.md"):
|
| 213 |
+
# with open(filename, "w", encoding="utf-8") as f:
|
| 214 |
+
# f.write(markdown_text)
|
| 215 |
+
# print(f"Markdown report saved as: {filename}")
|
| 216 |
+
|
| 217 |
+
# # -------------------------------------
|
| 218 |
+
# # MAIN
|
| 219 |
+
# # -------------------------------------
|
| 220 |
+
|
| 221 |
+
# if __name__ == "__main__":
|
| 222 |
+
# answers = load_answers("vpk_user_answers.json")
|
| 223 |
+
# dosha_counts = count_doshas(answers)
|
| 224 |
+
# # print(dosha_counts)
|
| 225 |
+
# personality_type = assign_personality(dosha_counts)
|
| 226 |
+
# # print(personality_type)
|
| 227 |
+
# traits_text = get_traits_for_type(personality_type)
|
| 228 |
+
# # print(traits_text)
|
| 229 |
+
|
| 230 |
+
# report_md = generate_psychology_report(personality_type, traits_text, dosha_counts)
|
| 231 |
+
|
| 232 |
+
# # save_report(report_md)
|
| 233 |
+
# # print("\nGenerated Report:\n")
|
| 234 |
+
# #print(report_md)
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
import json
|
| 241 |
+
import os
|
| 242 |
+
import random
|
| 243 |
+
from typing import Dict, Any
|
| 244 |
+
from fastapi import FastAPI, HTTPException
|
| 245 |
+
from pydantic import BaseModel
|
| 246 |
+
from groq import Groq
|
| 247 |
+
from dotenv import load_dotenv
|
| 248 |
+
import requests
|
| 249 |
+
from bson import ObjectId
|
| 250 |
+
|
| 251 |
+
from utils import get_random, get_mongo_collection
|
| 252 |
+
|
| 253 |
+
load_dotenv()
|
| 254 |
+
|
| 255 |
+
app = FastAPI(title="KPV asessment API")
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
some = get_random()
|
| 259 |
+
GROQ_API_KEY = os.getenv(f"GROQ_API_KEY{some}")
|
| 260 |
+
client = Groq(api_key=GROQ_API_KEY)
|
| 261 |
+
|
| 262 |
+
class ReportRequest(BaseModel):
|
| 263 |
+
user_id: str
|
| 264 |
+
username: str
|
| 265 |
+
|
| 266 |
+
class ReportResponse(BaseModel):
|
| 267 |
+
user_id: str
|
| 268 |
+
personality_type: str
|
| 269 |
+
dosha_counts: Dict[str, int]
|
| 270 |
+
report_markdown: str
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def count_doshas(userid):
|
| 275 |
+
collection = get_mongo_collection()
|
| 276 |
+
cursor = collection.find({"templateName": "Kapha,Pitta,Vata","userId": userid}).sort("createdAt", -1).limit(1)
|
| 277 |
+
|
| 278 |
+
mapping = {'1': 'Vata', '2': 'Pitta', '3': 'Kapha'}
|
| 279 |
+
counts = {"Vata": 0, "Pitta": 0, "Kapha": 0}
|
| 280 |
+
|
| 281 |
+
found_data = False
|
| 282 |
+
for item in cursor:
|
| 283 |
+
found_data = True
|
| 284 |
+
if "answers" in item:
|
| 285 |
+
for lst in item["answers"]:
|
| 286 |
+
if 'answer' in lst and lst['answer']:
|
| 287 |
+
key = lst['answer'][:1]
|
| 288 |
+
if key in mapping:
|
| 289 |
+
counts[mapping[key]] += 1
|
| 290 |
+
|
| 291 |
+
if not found_data:
|
| 292 |
+
return None
|
| 293 |
+
|
| 294 |
+
return counts
|
| 295 |
+
|
| 296 |
+
def assign_personality(counts):
|
| 297 |
+
v = counts["Vata"]
|
| 298 |
+
p = counts["Pitta"]
|
| 299 |
+
k = counts["Kapha"]
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
if v >= 7: return "Vata"
|
| 303 |
+
if p >= 7: return "Pitta"
|
| 304 |
+
if k >= 7: return "Kapha"
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
if v >= 5 and p >= 5: return "Vata-Pitta"
|
| 308 |
+
if p >= 5 and k >= 5: return "Pitta-Kapha"
|
| 309 |
+
if v >= 5 and k >= 5: return "Vata-Kapha"
|
| 310 |
+
|
| 311 |
+
if v >= 3 and p >= 3 and k >= 3: return "Vata-Pitta-Kapha"
|
| 312 |
+
|
| 313 |
+
return "Unclear"
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
TRAITS = {
|
| 318 |
+
"Vata": """
|
| 319 |
+
Vata
|
| 320 |
+
Vata types are quick and agile in their minds with often changing
|
| 321 |
+
interests and inclinations. They are talkative, informed and
|
| 322 |
+
intellectual and can understand many different points of view their minds easily
|
| 323 |
+
waver and can wander out of control. While they may have some knowledge of many
|
| 324 |
+
different subjects, the tend to lack in depth knowledge about one subject specifically.
|
| 325 |
+
|
| 326 |
+
They ack determinism and self confidence and often have a negative perception of themselves.
|
| 327 |
+
Vata types suffer most from fear, which is their first reaction to anything new or strange. They like to worry easily get afflicted by anxiety, and usually lack stability. They get saced out and may be absent-minded. Their memory and short-term and erratic. They suffer quickly from overwork and over-exercise and tend to overextend themselves in whatever they do.
|
| 328 |
+
They are good at creative pursuits. They can be highly sociable and like to mix with people of all types. But, when there is too much vata, they tend to become loners and hypersensitive to contact. This is generally because they have too much to say and do not know how to relate it.
|
| 329 |
+
|
| 330 |
+
They are the most adaptable to change.
|
| 331 |
+
|
| 332 |
+
If there is too much vata, there is a lot of instability and agitation in the mind which results in exccesive worrying and makes problems appear larger than they are. They are prone to premature action and inappropriate action.
|
| 333 |
+
|
| 334 |
+
High vata manifests as fear, alienation, and possible nervous breakdowns. They can also suffer from insomnia, tremors, palpitations and rapid shifts of mood.
|
| 335 |
+
""",
|
| 336 |
+
|
| 337 |
+
"Pitta": """
|
| 338 |
+
Pitta
|
| 339 |
+
Pitta types are intelligent, perceptive and discriminating. They have sharp minds and are able to see the world in a clear and systematic manner. However, they can also be opinionated, judgmental and self -righteous.
|
| 340 |
+
|
| 341 |
+
They are prone to anger and tend to be aggressive and domineering. They are not afraid of conflict and can be more aggressive when the situation presents itself. They have probing minds and can be good at research. They also have good debating skills.
|
| 342 |
+
|
| 343 |
+
They have a hard time seeing someone else’s point of view and may lack compassion. They prefer hierarchy and authority over consensus. They are highly determined people.
|
| 344 |
+
|
| 345 |
+
They usually have food self-control but they can be self-absorbed and anti-social.
|
| 346 |
+
|
| 347 |
+
High pitta causes aggressiveness and violence.
|
| 348 |
+
""",
|
| 349 |
+
|
| 350 |
+
"Kapha": """
|
| 351 |
+
Kapha
|
| 352 |
+
Kaphas are naturally emotional in temperament and have tremendous love, devotion and loyalty. Negatively, they can have great desire, and may be possessive and greedy. They are romantic, sentimental, and cry easily.
|
| 353 |
+
|
| 354 |
+
They are slower in learning than others but they retain what they learn well. They are better at finishing things than they are at starting something new. They are natural followers and like to work in association or within large teams.
|
| 355 |
+
|
| 356 |
+
They are stable but can sometimes stagnate. They don’t like change and find it very difficult to change even when they want to. They are friendly to people they know but have difficulty in relating to foreigners.
|
| 357 |
+
|
| 358 |
+
Kapha types are least likely to express anti-social behavior but they are preoccupied with what others think about them.
|
| 359 |
+
|
| 360 |
+
High kaha cuses metal dullness and poor perception and they tend to suffer from a lack of motivation.
|
| 361 |
+
|
| 362 |
+
They tend to want to own and control everything and have a high degree of possessiveness
|
| 363 |
+
|
| 364 |
+
They are prone to over-sleeping overindulging.
|
| 365 |
+
""",
|
| 366 |
+
|
| 367 |
+
"Vata-Pitta": """
|
| 368 |
+
Vata – Pitta (VP)
|
| 369 |
+
VP types have the volatility of air and fire combined. Fear and anger mix within them in unpredictable way. If something doesn’t make them fearful, it makes them angry.
|
| 370 |
+
|
| 371 |
+
They often look for someone who they can unload their negative emotions on.
|
| 372 |
+
|
| 373 |
+
They find it difficult to withstand criticism.
|
| 374 |
+
|
| 375 |
+
They are generally highly intelligent and require a lifestyle that can accommodate their volatility.
|
| 376 |
+
|
| 377 |
+
They will thrive in an environment that supports them and creates a safe space for them to express their volatility.
|
| 378 |
+
""",
|
| 379 |
+
|
| 380 |
+
"Pitta-Kapha": """
|
| 381 |
+
Pitta – Kapha (PK)
|
| 382 |
+
Pitta kapha types are psychologically strong in general and don’t seek help easily.
|
| 383 |
+
|
| 384 |
+
They lack flexibility and adaptability.
|
| 385 |
+
|
| 386 |
+
They prefer to be dominating and controlling.
|
| 387 |
+
|
| 388 |
+
They tend to be conservative and possessive. This leads them to eventual frustration because they cannot control everything around them.
|
| 389 |
+
|
| 390 |
+
They require new activities, new challenges, and new ways to show their creativity.
|
| 391 |
+
""",
|
| 392 |
+
|
| 393 |
+
"Vata-Kapha": """
|
| 394 |
+
Vata – Kapha (VK)
|
| 395 |
+
VK types lack energy, motivation and passion. They sometimes simply do not have the fire to get things started.
|
| 396 |
+
|
| 397 |
+
They are often hypersensitive, and passive-dependent.
|
| 398 |
+
|
| 399 |
+
They lack the energy to put plans into action.
|
| 400 |
+
|
| 401 |
+
They will go out of their way to agree with what you have said.
|
| 402 |
+
|
| 403 |
+
They have chameleon-style personalities where they can appear to be what people want them to be. They will often also blame themselves for others’ mistakes.
|
| 404 |
+
|
| 405 |
+
They can be highly adaptable and humble.
|
| 406 |
+
|
| 407 |
+
They tend to be naïve and need to be more realistic about other people and their motivations.
|
| 408 |
+
""",
|
| 409 |
+
|
| 410 |
+
"Vata-Pitta-Kapha": """
|
| 411 |
+
Vata – Pitta – Kapha (VPK)
|
| 412 |
+
This is very rare that each of the doshas exist in equal amounts.
|
| 413 |
+
|
| 414 |
+
Their condition psychologically can be constantly changing and unpredictable.
|
| 415 |
+
|
| 416 |
+
Their psychological state is often a reflection of their circumstances rather than their personality.
|
| 417 |
+
"""
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
def get_traits_for_type(personality_type):
|
| 421 |
+
return TRAITS.get(personality_type, "No traits found for this type.")
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
def generate_psychology_report(personality_type, traits_text, dosha_counts, request: ReportRequest):
|
| 425 |
+
prompt = f"""
|
| 426 |
+
You are an expert Ayurvedic psychologist.
|
| 427 |
+
|
| 428 |
+
Write a **deeply personal psychological report directly addressing the person as "you"**.
|
| 429 |
+
You can start with greetings and name of the person: {request.username}
|
| 430 |
+
This should NOT sound like an academic explanation — it should feel like an
|
| 431 |
+
insightful evaluation about them.
|
| 432 |
+
|
| 433 |
+
### REQUIRED STYLE:
|
| 434 |
+
- Address the reader as **"you"** throughout
|
| 435 |
+
- Tone: warm, empathetic, reflective, personal
|
| 436 |
+
- Use gentle interpretations (“you often…”, “you tend to…”, “you sometimes struggle…”)
|
| 437 |
+
- Explore emotional patterns, thought styles, reactions, strengths, blindspots
|
| 438 |
+
|
| 439 |
+
**Formatting Instructions:**
|
| 440 |
+
- The output MUST be in **Markdown**.
|
| 441 |
+
- Use `#` for the Main Title (e.g., # Personality Report Report).
|
| 442 |
+
- Use `##` for Section Headers (e.g., ## Core Personality).
|
| 443 |
+
- Use bullet points `- ` for lists.
|
| 444 |
+
- Use **bold** text for key strengths or warnings.
|
| 445 |
+
- Do not wrap the output in a code block (like ```markdown). Just return the raw markdown.
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
### Input Data
|
| 449 |
+
Personality Type: **{personality_type}**
|
| 450 |
+
Dosha Counts: {dosha_counts}
|
| 451 |
+
|
| 452 |
+
Relevant Ayurvedic Traits:
|
| 453 |
+
--------------------------
|
| 454 |
+
{traits_text}
|
| 455 |
+
|
| 456 |
+
Begin the personal Markdown report now.
|
| 457 |
+
"""
|
| 458 |
+
|
| 459 |
+
completion = client.chat.completions.create(
|
| 460 |
+
model="openai/gpt-oss-20b", # Ensure this model ID is correct for your Groq access
|
| 461 |
+
temperature=0.5,
|
| 462 |
+
max_tokens=4000,
|
| 463 |
+
messages=[
|
| 464 |
+
{"role": "system", "content": "You write personal Ayurvedic psychological reports"},
|
| 465 |
+
{"role": "user", "content": prompt}
|
| 466 |
+
]
|
| 467 |
+
)
|
| 468 |
+
|
| 469 |
+
return completion.choices[0].message.content
|
| 470 |
+
|
| 471 |
+
|
| 472 |
+
@app.get("/")
|
| 473 |
+
def home():
|
| 474 |
+
return {"status": "Ayurvedic Report Service is Running"}
|
| 475 |
+
|
| 476 |
+
@app.post("/cron_test_KPV")
|
| 477 |
+
async def cron_test():
|
| 478 |
+
return "Hello Cron Tester"
|
| 479 |
+
|
| 480 |
+
|
| 481 |
+
@app.post("/generate-report", response_model=ReportResponse)
|
| 482 |
+
def create_report(request: ReportRequest):
|
| 483 |
+
try:
|
| 484 |
+
dosha_counts = count_doshas(request.user_id)
|
| 485 |
+
|
| 486 |
+
if dosha_counts is None:
|
| 487 |
+
raise HTTPException(status_code=404, detail="User data or survey answers not found")
|
| 488 |
+
|
| 489 |
+
personality_type = assign_personality(dosha_counts)
|
| 490 |
+
|
| 491 |
+
traits_text = get_traits_for_type(personality_type)
|
| 492 |
+
report_md = generate_psychology_report(personality_type, traits_text, dosha_counts,request)
|
| 493 |
+
|
| 494 |
+
return ReportResponse(
|
| 495 |
+
user_id=request.user_id,
|
| 496 |
+
personality_type=personality_type,
|
| 497 |
+
dosha_counts=dosha_counts,
|
| 498 |
+
report_markdown=report_md
|
| 499 |
+
)
|
| 500 |
+
|
| 501 |
+
except Exception as e:
|
| 502 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 503 |
+
|
| 504 |
+
# To run locally:
|
| 505 |
+
# uvicorn main:app --reload
|
psychology_report.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Your Personal Ayurvedic Psychological Report
|
| 2 |
+
|
| 3 |
+
## Who You Are at Core
|
| 4 |
+
|
| 5 |
+
- You carry the **dynamic rhythm of Vata** – lightness, creativity, and curiosity that keep you moving forward.
|
| 6 |
+
- You also carry the **fiery focus of Pitta** – determination, sharp intellect, and a drive that can light up projects.
|
| 7 |
+
- Together, Vata and Pitta form a unique energy pattern: you can be **energetic yet unpredictable**; thoughtful yet quick to react when emotions surge.
|
| 8 |
+
|
| 9 |
+
## Emotional Landscape
|
| 10 |
+
|
| 11 |
+
- You often feel **fear turning swiftly into anger**, especially when something unsettles you or feels beyond your control.
|
| 12 |
+
- Because of this volatility, you seek a confidant or a partner with whom you can **unload and process those intense feelings**.
|
| 13 |
+
- When confronted with criticism, you tend to take it personally, feeling it as a direct challenge to your worth or intelligence.
|
| 14 |
+
- This sensitivity can make you **hard to please or to soothe** once you've become upset—small setbacks can feel magnified.
|
| 15 |
+
|
| 16 |
+
## Thought Patterns and Strengths
|
| 17 |
+
|
| 18 |
+
- Your mind is a **powerful analytical engine** – you excel in problem‑solving, strategizing, and learning new concepts quickly.
|
| 19 |
+
- You have a **keen instinct for patterns** and can see connections that others might miss, making you brilliant in areas that require rapid adaptation.
|
| 20 |
+
- You are also **highly intuitive**, picking up subtle cues from people and environments, which often guides your decision‑making.
|
| 21 |
+
|
| 22 |
+
### Key Strengths
|
| 23 |
+
- **Innovative mindset** – you generate fresh ideas and challenge the status quo.
|
| 24 |
+
- **Intellectual curiosity** – you crave knowledge and enjoy diving deep into subjects that ignite your passion.
|
| 25 |
+
- **Flexibility** – you can pivot quickly when new information or a new direction comes up.
|
| 26 |
+
|
| 27 |
+
## Blind Spots You Might Not Notice
|
| 28 |
+
|
| 29 |
+
- The blend of Vata’s lightness with Pitta’s intensity can cause **emotional turbulence** that feels out of control, leading to burnout if you don’t pause.
|
| 30 |
+
- Because you take criticism so personally, you sometimes **over‑question your abilities** even when evidence shows competence.
|
| 31 |
+
- Your desire to unload feelings may lead you to **lean heavily on one relationship**, which can unbalance both your and their emotional well‑being.
|
| 32 |
+
|
| 33 |
+
## What Helps You Thrive
|
| 34 |
+
|
| 35 |
+
- Create **safe spaces** where you can vent without judgment—a trusted friend, a counselor, or a reflective journal.
|
| 36 |
+
- Establish a **consistent routine**: regular meal times, moderate exercise, and enough sleep anchor the Vata energy and temper the Pitta fire.
|
| 37 |
+
- Practice **mindfulness** or guided breathing to help you catch the early signs of rising anxiety or irritation before they turn into anger.
|
| 38 |
+
- Set boundaries in relationships: let others know when you need space to process feelings, and encourage mutual support.
|
| 39 |
+
|
| 40 |
+
## Personal Tips for Balance
|
| 41 |
+
|
| 42 |
+
- **Daily grounding ritual** – a brief grounding meditation (focus on the breath and visualizing roots extending into the earth) can calm the volatile mind.
|
| 43 |
+
- **Use affirmations** that remind you of your inner resilience and that criticism is a tool, not a verdict.
|
| 44 |
+
- **Schedule regular check‑ins** with a supportive ally—this keeps you from bottling emotions and encourages constructive expression.
|
| 45 |
+
- **Keep a gratitude log** each day to re‑anchor your emotions in positivity; it counters the tendency toward fear and anger.
|
| 46 |
+
|
| 47 |
+
## Final Reflection
|
| 48 |
+
|
| 49 |
+
You are a vibrant tapestry of moving air and rising flame. The very qualities that make you brilliant can also stir unrest when not balanced. By honoring both your imaginative spirit and your analytical drive—and by giving yourself the gentle, structured care that Vata‑Pitta need—you can turn volatility into a powerful ally, turning each challenge into an opportunity for growth. Remember: you deserve calm, you deserve understanding, and you are fully capable of finding both within yourself.
|
utils.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
import itertools
|
| 4 |
+
from groq import Groq
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
from pymongo import MongoClient
|
| 7 |
+
import random
|
| 8 |
+
import certifi
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def get_random():
|
| 13 |
+
lst = ["R1","R2","R3","S1","RD1"]
|
| 14 |
+
i = random.randint(0,4)
|
| 15 |
+
return lst[i]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def get_mongo_collection():
|
| 20 |
+
CONNECTION_STRING = os.getenv("CONNECTION_STRING")
|
| 21 |
+
DB_NAME = os.getenv("DB_NAME")
|
| 22 |
+
COLLECTION_NAME = os.getenv("COLLECTION_NAME")
|
| 23 |
+
try:
|
| 24 |
+
# Connect with certifi to avoid SSL errors
|
| 25 |
+
client = MongoClient(CONNECTION_STRING, tlsCAFile=certifi.where())
|
| 26 |
+
db = client[DB_NAME]
|
| 27 |
+
return db[COLLECTION_NAME]
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print(f"Error connecting to Mongo: {e}")
|
| 30 |
+
return None
|
vpk_user_answers.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"category": "Memory",
|
| 4 |
+
"question": "Which of the following best describes your memory?",
|
| 5 |
+
"selectedOption": "Vata"
|
| 6 |
+
},
|
| 7 |
+
{
|
| 8 |
+
"category": "Concentration",
|
| 9 |
+
"question": "How easy is it for you to focus on something or someone for an extended period of time?",
|
| 10 |
+
"selectedOption": "Vata"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"category": "Changes to Plans",
|
| 14 |
+
"question": "How would you react if there was a sudden change in your schedule?",
|
| 15 |
+
"selectedOption": "Vata"
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"category": "Appeal to change",
|
| 19 |
+
"question": "What is the main reason you may be convinced to change your mind about something?",
|
| 20 |
+
"selectedOption": "Vata"
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"category": "Story-telling",
|
| 24 |
+
"question": "How do you tell stories about events or experiences in your life?",
|
| 25 |
+
"selectedOption": "Vata"
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"category": "Style of work",
|
| 29 |
+
"question": "Which of the following best describes your style of work?",
|
| 30 |
+
"selectedOption": "Vata"
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"category": "Learning",
|
| 34 |
+
"question": "Which of the following best describes how you learn a new concept?",
|
| 35 |
+
"selectedOption": "Kapha"
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"category": "Dreams",
|
| 39 |
+
"question": "How often do you dream?",
|
| 40 |
+
"selectedOption": "Vata"
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"category": "Reaction",
|
| 44 |
+
"question": "What is your first reaction to something new or strange?",
|
| 45 |
+
"selectedOption": "Pitta"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"category": "Leadership",
|
| 49 |
+
"question": "How do you tend to interact with a team or a group of people?",
|
| 50 |
+
"selectedOption": "Kapha"
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"category": "Starting something new",
|
| 54 |
+
"question": "How easily do you start something new?",
|
| 55 |
+
"selectedOption": "Vata"
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"category": "Planning",
|
| 59 |
+
"question": "How do you usually like to make plans?",
|
| 60 |
+
"selectedOption": "Pitta"
|
| 61 |
+
}
|
| 62 |
+
]
|