Spaces:
Runtime error
Runtime error
first commit
Browse files- app.py +247 -0
- chain_problems.py +163 -0
- chain_recommendations.py +67 -0
- chain_reports.py +31 -0
- chain_summary.py +40 -0
- config.py +16 -0
- models.py +8 -0
- pipeline.py +41 -0
- questions.py +31 -0
- requirements.txt +7 -0
app.py
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import json
|
| 4 |
+
import re
|
| 5 |
+
from pipeline import process_answers_pipeline
|
| 6 |
+
from questions import questions
|
| 7 |
+
|
| 8 |
+
def extract_report_content(report_text):
|
| 9 |
+
"""Extract the actual report content from the report field."""
|
| 10 |
+
try:
|
| 11 |
+
if isinstance(report_text, str) and report_text.startswith('{'):
|
| 12 |
+
report_dict = eval(report_text)
|
| 13 |
+
return report_dict.get('report', '').strip()
|
| 14 |
+
except:
|
| 15 |
+
pass
|
| 16 |
+
return report_text.strip()
|
| 17 |
+
|
| 18 |
+
def parse_recommendation_array_and_text(raw_recommendation):
|
| 19 |
+
"""
|
| 20 |
+
1) Extract the bracketed JSON array of packages
|
| 21 |
+
2) Return the remainder of the text for further parsing.
|
| 22 |
+
"""
|
| 23 |
+
array_match = re.search(r'\[(.*?)\]', raw_recommendation, flags=re.DOTALL)
|
| 24 |
+
if array_match:
|
| 25 |
+
try:
|
| 26 |
+
packages_list = json.loads(f"[{array_match.group(1)}]")
|
| 27 |
+
packages_list = [p.strip() for p in packages_list if isinstance(p, str)]
|
| 28 |
+
except:
|
| 29 |
+
packages_list = []
|
| 30 |
+
else:
|
| 31 |
+
packages_list = []
|
| 32 |
+
|
| 33 |
+
end_of_array = array_match.end() if array_match else 0
|
| 34 |
+
remainder_text = raw_recommendation[end_of_array:].strip()
|
| 35 |
+
|
| 36 |
+
return packages_list, remainder_text
|
| 37 |
+
|
| 38 |
+
def parse_package_descriptions(text):
|
| 39 |
+
"""Parse package descriptions from text using regex."""
|
| 40 |
+
mental_match = re.search(
|
| 41 |
+
r"\*\*High Stress/Anxiety:\*\*(.*?)(?=\*\*|$)",
|
| 42 |
+
text,
|
| 43 |
+
flags=re.DOTALL
|
| 44 |
+
)
|
| 45 |
+
mental_text = mental_match.group(1).strip() if mental_match else ""
|
| 46 |
+
|
| 47 |
+
fitness_match = re.search(
|
| 48 |
+
r"\*\*Moderate Fitness & Mobility:\*\*(.*?)(?=\*\*|$)",
|
| 49 |
+
text,
|
| 50 |
+
flags=re.DOTALL
|
| 51 |
+
)
|
| 52 |
+
fitness_text = fitness_match.group(1).strip() if fitness_match else ""
|
| 53 |
+
|
| 54 |
+
gut_match = re.search(
|
| 55 |
+
r"\*\*Gut Health:\*\*(.*?)(?=\*\*|$)",
|
| 56 |
+
text,
|
| 57 |
+
flags=re.DOTALL
|
| 58 |
+
)
|
| 59 |
+
gut_text = gut_match.group(1).strip() if gut_match else ""
|
| 60 |
+
|
| 61 |
+
insomnia_match = re.search(
|
| 62 |
+
r"\*\*No More Insomnia:\*\*(.*?)(?=\*\*|$)",
|
| 63 |
+
text,
|
| 64 |
+
flags=re.DOTALL
|
| 65 |
+
)
|
| 66 |
+
insomnia_text = insomnia_match.group(1).strip() if insomnia_match else ""
|
| 67 |
+
|
| 68 |
+
just_match = re.search(
|
| 69 |
+
r"\*\*Justification for Exclusion:\*\*(.*?)(?=$)",
|
| 70 |
+
text,
|
| 71 |
+
flags=re.DOTALL
|
| 72 |
+
)
|
| 73 |
+
justification_text = just_match.group(1).strip() if just_match else ""
|
| 74 |
+
|
| 75 |
+
return {
|
| 76 |
+
"mental_wellness": mental_text,
|
| 77 |
+
"fitness_mobility": fitness_text,
|
| 78 |
+
"gut_health": gut_text,
|
| 79 |
+
"no_more_insomnia": insomnia_text,
|
| 80 |
+
"justification": justification_text
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
def process_answers(
|
| 84 |
+
sleep,
|
| 85 |
+
exercise,
|
| 86 |
+
mood,
|
| 87 |
+
stress_level,
|
| 88 |
+
wellness_goals,
|
| 89 |
+
dietary_restrictions,
|
| 90 |
+
relaxation_time,
|
| 91 |
+
health_issues,
|
| 92 |
+
water_intake,
|
| 93 |
+
gratitude_feelings,
|
| 94 |
+
connection_rating,
|
| 95 |
+
energy_rating
|
| 96 |
+
):
|
| 97 |
+
responses = {
|
| 98 |
+
questions[0]: sleep,
|
| 99 |
+
questions[1]: exercise,
|
| 100 |
+
questions[2]: mood,
|
| 101 |
+
questions[3]: stress_level,
|
| 102 |
+
questions[4]: wellness_goals,
|
| 103 |
+
questions[5]: dietary_restrictions,
|
| 104 |
+
questions[7]: relaxation_time,
|
| 105 |
+
questions[8]: health_issues,
|
| 106 |
+
questions[12]: water_intake,
|
| 107 |
+
questions[23]: gratitude_feelings,
|
| 108 |
+
questions[24]: connection_rating,
|
| 109 |
+
questions[27]: energy_rating
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
try:
|
| 113 |
+
# Run the pipeline
|
| 114 |
+
results = process_answers_pipeline(responses)
|
| 115 |
+
|
| 116 |
+
# Capture the entire pipeline response as a string
|
| 117 |
+
complete_response = str(results)# removed complete response
|
| 118 |
+
|
| 119 |
+
# Extract individual fields
|
| 120 |
+
wellness_report = extract_report_content(results.get('report', ''))
|
| 121 |
+
|
| 122 |
+
# Extract final_summary and shortened_summary
|
| 123 |
+
final_summary = results.get('final_summary', '')
|
| 124 |
+
shortened_summary = results.get('shortened_summary', '')
|
| 125 |
+
|
| 126 |
+
problems_data = results.get('problems', {})
|
| 127 |
+
identified_problems = {
|
| 128 |
+
"stress_management": float(str(problems_data.get('stress_management', 0)).replace('%', '')),
|
| 129 |
+
"low_therapy": float(str(problems_data.get('low_therapy', 0)).replace('%', '')),
|
| 130 |
+
"balanced_weight": float(str(problems_data.get('balanced_weight', 0)).replace('%', '')),
|
| 131 |
+
"restless_night": float(str(problems_data.get('restless_night', 0)).replace('%', '')),
|
| 132 |
+
"lack_of_motivation": float(str(problems_data.get('lack_of_motivation', 0)).replace('%', '')),
|
| 133 |
+
"gut_health": float(str(problems_data.get('gut_health', 0)).replace('%', '')),
|
| 134 |
+
"anxiety": float(str(problems_data.get('anxiety', 0)).replace('%', '')),
|
| 135 |
+
"burnout": float(str(problems_data.get('burnout', 0)).replace('%', ''))
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
raw_recommendation = results.get('recommendation', '').strip()
|
| 139 |
+
recommended_packages, remainder_text = parse_recommendation_array_and_text(raw_recommendation)
|
| 140 |
+
descriptions = parse_package_descriptions(remainder_text)
|
| 141 |
+
|
| 142 |
+
recommendations_with_description = []
|
| 143 |
+
for pkg in recommended_packages:
|
| 144 |
+
if pkg == "Mental Wellness":
|
| 145 |
+
final_desc = (
|
| 146 |
+
"**High Stress/Anxiety:** "
|
| 147 |
+
+ descriptions["mental_wellness"]
|
| 148 |
+
)
|
| 149 |
+
elif pkg == "Fitness & Mobility":
|
| 150 |
+
final_desc = (
|
| 151 |
+
"**Moderate Fitness & Mobility:** "
|
| 152 |
+
+ descriptions["fitness_mobility"]
|
| 153 |
+
)
|
| 154 |
+
elif pkg == "Gut Health":
|
| 155 |
+
final_desc = (
|
| 156 |
+
"**Gut Health:** "
|
| 157 |
+
+ descriptions["gut_health"]
|
| 158 |
+
)
|
| 159 |
+
elif pkg == "No More Insomnia":
|
| 160 |
+
final_desc = (
|
| 161 |
+
"**No More Insomnia:** "
|
| 162 |
+
+ descriptions["no_more_insomnia"]
|
| 163 |
+
)
|
| 164 |
+
else:
|
| 165 |
+
final_desc = ""
|
| 166 |
+
|
| 167 |
+
recommendations_with_description.append({
|
| 168 |
+
"package": pkg,
|
| 169 |
+
"description": final_desc
|
| 170 |
+
})
|
| 171 |
+
|
| 172 |
+
return {
|
| 173 |
+
# "complete_response": complete_response,# removed complete response
|
| 174 |
+
"wellness_report": wellness_report,
|
| 175 |
+
"identified_problems": identified_problems,
|
| 176 |
+
"recommended_packages": recommended_packages,
|
| 177 |
+
"recommendations_with_description": recommendations_with_description,
|
| 178 |
+
"exclusion_justification": descriptions["justification"],
|
| 179 |
+
"user summary": final_summary, # ADDED
|
| 180 |
+
"video script": shortened_summary # ADDED
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
except Exception as e:
|
| 184 |
+
return {
|
| 185 |
+
"error": f"Error processing answers: {str(e)}",
|
| 186 |
+
"complete_response": str(results) if 'results' in locals() else "No results generated"
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
# Create the Gradio interface
|
| 190 |
+
with gr.Blocks() as demo:
|
| 191 |
+
gr.Markdown("# Wellness Assessment")
|
| 192 |
+
|
| 193 |
+
with gr.Row():
|
| 194 |
+
with gr.Column():
|
| 195 |
+
sleep = gr.Textbox(
|
| 196 |
+
label="How many hours of sleep do you get each night?"
|
| 197 |
+
)
|
| 198 |
+
exercise = gr.Textbox(
|
| 199 |
+
label="How often do you exercise in a week?"
|
| 200 |
+
)
|
| 201 |
+
mood = gr.Textbox(
|
| 202 |
+
label="On a scale of 1 to 10, how would you rate your mood today?"
|
| 203 |
+
)
|
| 204 |
+
stress_level = gr.Textbox(
|
| 205 |
+
label="On a scale from 1 to 10, what is your current stress level?"
|
| 206 |
+
)
|
| 207 |
+
wellness_goals = gr.Textbox(
|
| 208 |
+
label="What are your primary wellness goals?"
|
| 209 |
+
)
|
| 210 |
+
dietary_restrictions = gr.Textbox(
|
| 211 |
+
label="Do you follow any specific diet or have any dietary restrictions?"
|
| 212 |
+
)
|
| 213 |
+
relaxation_time = gr.Textbox(
|
| 214 |
+
label="How much time do you spend on relaxation or mindfulness activities daily?"
|
| 215 |
+
)
|
| 216 |
+
health_issues = gr.Textbox(
|
| 217 |
+
label="How would you rate your health and wellness on a scale of 1 to 10?"
|
| 218 |
+
)
|
| 219 |
+
water_intake = gr.Textbox(
|
| 220 |
+
label="How much water do you drink on average per day?"
|
| 221 |
+
)
|
| 222 |
+
gratitude_feelings = gr.Textbox(
|
| 223 |
+
label="How often do you experience feelings of gratitude or happiness?"
|
| 224 |
+
)
|
| 225 |
+
connection_rating = gr.Textbox(
|
| 226 |
+
label="On a scale from 1 to 10, how will you define your human relations ?"
|
| 227 |
+
)
|
| 228 |
+
energy_rating = gr.Textbox(
|
| 229 |
+
label="On a scale from 1 to 10, how would you rate your energy levels throughout the day?"
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
submit_btn = gr.Button("Submit")
|
| 233 |
+
output = gr.JSON()
|
| 234 |
+
|
| 235 |
+
submit_btn.click(
|
| 236 |
+
fn=process_answers,
|
| 237 |
+
inputs=[
|
| 238 |
+
sleep, exercise, mood, stress_level, wellness_goals,
|
| 239 |
+
dietary_restrictions, relaxation_time, health_issues,
|
| 240 |
+
water_intake, gratitude_feelings, connection_rating,
|
| 241 |
+
energy_rating
|
| 242 |
+
],
|
| 243 |
+
outputs=output
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
if __name__ == "__main__":
|
| 247 |
+
demo.launch()
|
chain_problems.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# chain_problems.py
|
| 2 |
+
import json
|
| 3 |
+
import logging
|
| 4 |
+
from typing import Dict
|
| 5 |
+
from langchain import PromptTemplate, LLMChain
|
| 6 |
+
from models import chat_model
|
| 7 |
+
|
| 8 |
+
logger = logging.getLogger(__name__)
|
| 9 |
+
|
| 10 |
+
problem_prompt_template = PromptTemplate(
|
| 11 |
+
input_variables=["responses", "internal_report"],
|
| 12 |
+
# template=(
|
| 13 |
+
# "You are a wellness analyst. You have the following user responses to health-related questions:\n"
|
| 14 |
+
# "{responses}\n\n"
|
| 15 |
+
# "You also have an internal analysis report:\n"
|
| 16 |
+
# "{internal_report}\n\n"
|
| 17 |
+
# "From these inputs, determine a 'problem severity percentage' for the user in the following areas: "
|
| 18 |
+
# "stress_management, low_therapy, balanced_weight, restless_night, lack_of_motivation, gut_health, anxiety, burnout.\n\n"
|
| 19 |
+
# "Consider how these severity percentages will later be used to recommend suitable wellness packages such as:\n\n"
|
| 20 |
+
# "1. Fitness Mobility:\n"
|
| 21 |
+
# "Our Fitness Mobility Package is designed to help you move better, feel stronger, and embrace an active lifestyle. This comprehensive program focuses on improving your flexibility, strength, and joint mobility through tailored exercises, mindful movement, and practical guidance.\n"
|
| 22 |
+
# "With a mix of yoga-inspired stretches, mobility drills, and functional exercises, this package aims to enhance your body's natural range of motion, reduce stiffness, and support injury prevention. Whether you're a beginner or a fitness enthusiast, our program is adaptable to all levels and lifestyles.\n\n"
|
| 23 |
+
# "2. Balance Weight:\n"
|
| 24 |
+
# "Achieve a healthier, more balanced weight with our Balance Weight Package—a holistic approach to weight management that prioritizes your overall well-being. This program combines personalized nutrition guidance, effective workout routines, and mindful lifestyle practices to help you reach and maintain your ideal weight sustainably.\n"
|
| 25 |
+
# "With expert tips on portion control, meal planning, and calorie balance, along with strategies to boost your metabolism and build strength, this package is perfect for anyone looking to shed extra weight or build healthy habits.\n\n"
|
| 26 |
+
# "3. No More Insomnia:\n"
|
| 27 |
+
# "Say goodbye to restless nights with our No More Insomnia Package—designed to help you enjoy deep, rejuvenating sleep every night. This comprehensive program focuses on restoring your natural sleep cycle through proven techniques like guided relaxation, breathing exercises, and mindfulness practices.\n"
|
| 28 |
+
# "Explore the benefits of calming nighttime routines, sleep-friendly nutrition, and stress management tools, all tailored to help you fall asleep faster and wake up feeling refreshed. Whether you're battling occasional sleeplessness or chronic insomnia, this package empowers you to reclaim your rest naturally and effectively.\n\n"
|
| 29 |
+
# "4. Chronic Care:\n"
|
| 30 |
+
# "Manage chronic conditions with ease and confidence through our Chronic Care Package, thoughtfully designed to support your long-term health and well-being. This package provides a holistic approach to managing conditions like diabetes, hypertension, arthritis, and more by combining expert wellness guidance with practical, sustainable strategies.\n"
|
| 31 |
+
# "Discover personalized nutrition plans, stress-relief techniques, gentle mobility exercises, and mindfulness practices tailored to your needs. Our focus is on empowering you to lead a healthier, more active life while minimizing discomfort and promoting overall vitality.\n\n"
|
| 32 |
+
# "5. Mental Wellness:\n"
|
| 33 |
+
# "Prioritize your peace of mind with our Mental Wellness Package, crafted to help you navigate stress, anxiety, and emotional challenges while fostering a calm and balanced life. This package integrates ancient practices with modern techniques, offering a well-rounded approach to mental well-being.\n"
|
| 34 |
+
# "Explore guided meditation, breathing exercises, and mindfulness techniques designed to reduce stress and enhance focus. Pair these with personalized self-care routines, Ayurvedic insights, and strategies for improving sleep quality to rejuvenate your mind and body.\n"
|
| 35 |
+
# "Take the first step toward emotional resilience and inner harmony—because your mental health matters.\n\n"
|
| 36 |
+
# "6. Focus Flow:\n"
|
| 37 |
+
# "Unlock your productivity potential with the Focus Flow Package, designed to sharpen your concentration, boost creativity, and help you achieve a state of effortless focus. Whether you're tackling work, studies, or creative pursuits, this package provides tools to elevate your mental clarity and efficiency.\n"
|
| 38 |
+
# "Delve into focus-enhancing meditation techniques, mindful breathing exercises, and brain-boosting nutritional guidance. With insights from yoga and Ayurveda, you'll learn how to create an environment and routine that supports sustained attention and peak performance.\n"
|
| 39 |
+
# "Step into the flow and get more done—without the overwhelm!\n\n"
|
| 40 |
+
# "Consider the following connections between the questions and these themes:\n"
|
| 41 |
+
# "- stress_management is influenced by responses such as stress_level, stress_management, mood, mindfulness_frequency, and similar stress-related questions.\n"
|
| 42 |
+
# "- low_therapy relates to aspects of the user's mindset, wellness_goals, personal_growth_reflection, and similar therapeutic indicators.\n"
|
| 43 |
+
# "- balanced_weight depends on exercise, eating_habits, dietary_restrictions, activity_tracking, and other fitness/nutrition details.\n"
|
| 44 |
+
# "- restless_night is linked to answers about sleep duration, bedtime_routine, uninterrupted_sleep, and other sleep quality indicators.\n"
|
| 45 |
+
# "- lack_of_motivation correlates with mood, energy_rating, personal_growth_reflection, break_frequency, and similar motivation-related queries.\n"
|
| 46 |
+
# "- gut_health is connected to eating_habits, dietary_restrictions, health_issues, and other digestive or nutritional feedback.\n"
|
| 47 |
+
# "- anxiety is associated with responses about mood, stress_level, mindset, and related emotional well-being questions.\n"
|
| 48 |
+
# "- burnout may be reflected in high stress_level, low energy_rating, lack_of_motivation, and related fatigue or overwhelm indicators.\n\n"
|
| 49 |
+
# "Return your answer in JSON format with keys: stress_management, low_therapy, balanced_weight, restless_night, "
|
| 50 |
+
# "lack_of_motivation, gut_health, anxiety, burnout.\n"
|
| 51 |
+
# "Ensure severity percentages are numbers from 0 to 100.\n\n"
|
| 52 |
+
# "JSON Output:"
|
| 53 |
+
# )
|
| 54 |
+
template= (
|
| 55 |
+
"You are a wellness analyst conducting a detailed assessment. Analyze the following inputs:\n"
|
| 56 |
+
"1. User Responses to Health Questions:\n{responses}\n\n"
|
| 57 |
+
"2. Internal Analysis Report:\n{internal_report}\n\n"
|
| 58 |
+
"EVALUATION GUIDELINES:\n"
|
| 59 |
+
"Calculate a severity score (0-100) for each area using these criteria:\n"
|
| 60 |
+
"- 0-20: Minimal concern, good management\n"
|
| 61 |
+
"- 21-40: Mild concerns, potential for improvement\n"
|
| 62 |
+
"- 41-60: Moderate issues requiring attention\n"
|
| 63 |
+
"- 61-80: Significant challenges needing intervention\n"
|
| 64 |
+
"- 81-100: Severe issues requiring immediate attention\n\n"
|
| 65 |
+
"SCORING CRITERIA BY AREA:\n\n"
|
| 66 |
+
"1. Stress Management Score:\n"
|
| 67 |
+
"- Primary Indicators: stress_level, mood_rating\n"
|
| 68 |
+
"- Secondary Indicators: mindfulness_practice, relaxation_time\n"
|
| 69 |
+
"- Score Higher If: high stress, low mood, minimal relaxation time\n\n"
|
| 70 |
+
"2. Low Therapy Score:\n"
|
| 71 |
+
"- Primary Indicators: wellness_goals, personal_growth\n"
|
| 72 |
+
"- Secondary Indicators: emotional_support, self_reflection\n"
|
| 73 |
+
"- Score Higher If: limited support systems, unclear wellness goals\n\n"
|
| 74 |
+
"3. Balanced Weight Score:\n"
|
| 75 |
+
"- Primary Indicators: exercise_frequency, dietary_habits\n"
|
| 76 |
+
"- Secondary Indicators: activity_level, nutrition_awareness\n"
|
| 77 |
+
"- Score Higher If: irregular exercise, poor dietary habits\n\n"
|
| 78 |
+
"4. Restless Night Score:\n"
|
| 79 |
+
"- Primary Indicators: sleep_duration, sleep_quality\n"
|
| 80 |
+
"- Secondary Indicators: bedtime_routine, energy_levels\n"
|
| 81 |
+
"- Score Higher If: <7 or >9 hours sleep, poor sleep quality\n\n"
|
| 82 |
+
"5. Lack of Motivation Score:\n"
|
| 83 |
+
"- Primary Indicators: energy_rating, goal_completion\n"
|
| 84 |
+
"- Secondary Indicators: daily_activity, productivity\n"
|
| 85 |
+
"- Score Higher If: low energy, difficulty completing tasks\n\n"
|
| 86 |
+
"6. Gut Health Score:\n"
|
| 87 |
+
"- Primary Indicators: dietary_restrictions, digestive_issues\n"
|
| 88 |
+
"- Secondary Indicators: water_intake, eating_patterns\n"
|
| 89 |
+
"- Score Higher If: frequent digestive issues, poor diet\n\n"
|
| 90 |
+
"7. Anxiety Score:\n"
|
| 91 |
+
"- Primary Indicators: stress_level, worry_frequency\n"
|
| 92 |
+
"- Secondary Indicators: social_comfort, relaxation_ability\n"
|
| 93 |
+
"- Score Higher If: high stress, frequent worrying\n\n"
|
| 94 |
+
"8. Burnout Score:\n"
|
| 95 |
+
"- Primary Indicators: energy_level, work_life_balance\n"
|
| 96 |
+
"- Secondary Indicators: recovery_time, stress_management\n"
|
| 97 |
+
"- Score Higher If: low energy, poor work-life balance\n\n"
|
| 98 |
+
"AVAILABLE WELLNESS PACKAGES FOR REFERENCE:\n\n"
|
| 99 |
+
"1. Fitness Mobility\n"
|
| 100 |
+
"Focus: Movement, flexibility, strength, injury prevention\n"
|
| 101 |
+
"Best For: Limited mobility, stiffness, fitness goals\n\n"
|
| 102 |
+
"2. Balance Weight\n"
|
| 103 |
+
"Focus: Weight management, nutrition, sustainable habits\n"
|
| 104 |
+
"Best For: Weight concerns, dietary improvements\n\n"
|
| 105 |
+
"3. No More Insomnia\n"
|
| 106 |
+
"Focus: Sleep quality, relaxation, natural rest\n"
|
| 107 |
+
"Best For: Sleep issues, poor sleep quality\n\n"
|
| 108 |
+
"4. Chronic Care\n"
|
| 109 |
+
"Focus: Long-term health management, ongoing support\n"
|
| 110 |
+
"Best For: Chronic conditions, persistent health issues\n\n"
|
| 111 |
+
"5. Mental Wellness\n"
|
| 112 |
+
"Focus: Stress management, emotional balance\n"
|
| 113 |
+
"Best For: Anxiety, stress, emotional challenges\n\n"
|
| 114 |
+
"6. Focus Flow\n"
|
| 115 |
+
"Focus: Concentration, productivity, mental clarity\n"
|
| 116 |
+
"Best For: Motivation issues, focus challenges\n\n"
|
| 117 |
+
"OUTPUT INSTRUCTIONS:\n"
|
| 118 |
+
"Return your answer in JSON format with keys: stress_management, low_therapy, balanced_weight, restless_night, "
|
| 119 |
+
"lack_of_motivation, gut_health, anxiety, burnout.\n"
|
| 120 |
+
"Ensure severity percentages are numbers from 0 to 100.\n\n"
|
| 121 |
+
"JSON Output:"
|
| 122 |
+
)
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
problem_chain = LLMChain(llm=chat_model, prompt=problem_prompt_template)
|
| 126 |
+
|
| 127 |
+
def analyze_problems_with_chain(responses: Dict[str, str], internal_report: str) -> Dict[str, float]:
|
| 128 |
+
responses_str = "\n".join(f"{q}: {a}" for q, a in responses.items())
|
| 129 |
+
raw_text = problem_chain.run(responses=responses_str, internal_report=internal_report)
|
| 130 |
+
try:
|
| 131 |
+
# Extract JSON from the LLM output
|
| 132 |
+
start_idx = raw_text.find('{')
|
| 133 |
+
end_idx = raw_text.rfind('}') + 1
|
| 134 |
+
json_str = raw_text[start_idx:end_idx]
|
| 135 |
+
problems = json.loads(json_str)
|
| 136 |
+
|
| 137 |
+
# Ensure all eight keys are present with default values
|
| 138 |
+
for key in [
|
| 139 |
+
"stress_management",
|
| 140 |
+
"low_therapy",
|
| 141 |
+
"balanced_weight",
|
| 142 |
+
"restless_night",
|
| 143 |
+
"lack_of_motivation",
|
| 144 |
+
"gut_health",
|
| 145 |
+
"anxiety",
|
| 146 |
+
"burnout"
|
| 147 |
+
]:
|
| 148 |
+
problems.setdefault(key, 0.0)
|
| 149 |
+
|
| 150 |
+
return {k: float(v) for k, v in problems.items()}
|
| 151 |
+
except Exception as e:
|
| 152 |
+
logger.error(f"Error parsing problem percentages from LLM: {e}")
|
| 153 |
+
# Return default values for all eight themes in case of an error
|
| 154 |
+
return {
|
| 155 |
+
"stress_management": 0.0,
|
| 156 |
+
"low_therapy": 0.0,
|
| 157 |
+
"balanced_weight": 0.0,
|
| 158 |
+
"restless_night": 0.0,
|
| 159 |
+
"lack_of_motivation": 0.0,
|
| 160 |
+
"gut_health": 0.0,
|
| 161 |
+
"anxiety": 0.0,
|
| 162 |
+
"burnout": 0.0
|
| 163 |
+
}
|
chain_recommendations.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# chain_recommendations.py
|
| 2 |
+
import json
|
| 3 |
+
from typing import Dict
|
| 4 |
+
from langchain import PromptTemplate, LLMChain
|
| 5 |
+
from models import chat_model
|
| 6 |
+
|
| 7 |
+
#
|
| 8 |
+
# UPDATED PROMPT:
|
| 9 |
+
# We ask the LLM to return:
|
| 10 |
+
# 1) A JSON array (on its own line) listing the recommended packages
|
| 11 |
+
# 2) Followed by detailed headings explaining WHY each recommended package is chosen
|
| 12 |
+
# and possibly why other packages are excluded.
|
| 13 |
+
#
|
| 14 |
+
improved_recommend_prompt_template = PromptTemplate(
|
| 15 |
+
input_variables=["problems"],
|
| 16 |
+
template=(
|
| 17 |
+
"You are a wellness recommendation assistant. You receive problem severity percentages:\n"
|
| 18 |
+
"{problems}\n\n"
|
| 19 |
+
"We have these potential packages:\n"
|
| 20 |
+
"1. Fitness & Mobility | Tagline: 'Enhance Mobility. Boost Fitness.'\n"
|
| 21 |
+
"2. No More Insomnia | Deep Rest | Tagline: 'Reclaim Your Sleep. Restore Your Mind.'\n"
|
| 22 |
+
"3. Focus Flow | Clarity Boost | Tagline: 'Stay Focused. Stay Productive.'\n"
|
| 23 |
+
"4. Boost Energy | Tagline: 'Fuel Your Day. Boost Your Energy.'\n"
|
| 24 |
+
"5. Chronic Care | Chronic Support | Tagline: 'Ongoing Support for Chronic Wellness.'\n"
|
| 25 |
+
"6. Mental Wellness | Calm Mind | Tagline: 'Find Peace of Mind, Every Day.'\n\n"
|
| 26 |
+
"Carefully analyze these percentages, considering:\n"
|
| 27 |
+
"- If one area is extremely high (above 70), prioritize that area.\n"
|
| 28 |
+
"- If multiple areas are high (above 60), recommend multiple specialized packages.\n"
|
| 29 |
+
"- If all areas are moderate (30 to 70), suggest a balanced approach.\n"
|
| 30 |
+
"- If all areas are low, a general or minimal package might suffice.\n"
|
| 31 |
+
"- Consider borderline and preventative measures.\n\n"
|
| 32 |
+
"## IMPORTANT:\n"
|
| 33 |
+
"1) First, output the recommended packages in a strict JSON array format, for example:\n"
|
| 34 |
+
" ```json\n"
|
| 35 |
+
" [\n"
|
| 36 |
+
" \"Mental Wellness\",\n"
|
| 37 |
+
" \"Fitness & Mobility\"\n"
|
| 38 |
+
" ]\n"
|
| 39 |
+
" ```\n"
|
| 40 |
+
" Each item must be exactly one of these valid names:\n"
|
| 41 |
+
" \"Fitness & Mobility\", \"No More Insomnia\", \"Focus Flow\", \"Boost Energy\", \"Chronic Care\", \"Mental Wellness\".\n\n"
|
| 42 |
+
"2) After that JSON array, provide explanation/analysis under headings:\n"
|
| 43 |
+
" **High Stress/Anxiety:** ... (if relevant)\n"
|
| 44 |
+
" **Moderate Fitness & Mobility:** ... (if relevant)\n"
|
| 45 |
+
" **Gut Health:** ... (if relevant)\n"
|
| 46 |
+
" **No More Insomnia:** ... (if relevant)\n"
|
| 47 |
+
" **Focus Flow:** ...\n"
|
| 48 |
+
" **Justification for Exclusion:** ...\n"
|
| 49 |
+
" etc.\n\n"
|
| 50 |
+
"Make sure your headings are prefixed with double asterisks, e.g. `**High Stress/Anxiety:**`.\n\n"
|
| 51 |
+
"Return everything as a single string. The important part:\n"
|
| 52 |
+
" - The JSON array is fully valid JSON.\n"
|
| 53 |
+
" - After that, the text analysis uses headings.\n\n"
|
| 54 |
+
)
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
recommend_chain = LLMChain(llm=chat_model, prompt=improved_recommend_prompt_template)
|
| 58 |
+
|
| 59 |
+
def generate_recommendations(problems: Dict[str, float]) -> str:
|
| 60 |
+
"""
|
| 61 |
+
Runs the LLMChain with the updated prompt.
|
| 62 |
+
Returns a string containing:
|
| 63 |
+
1) A JSON array on its own line
|
| 64 |
+
2) Explanations for each recommended or excluded package.
|
| 65 |
+
"""
|
| 66 |
+
recommendations = recommend_chain.run(problems=json.dumps(problems))
|
| 67 |
+
return recommendations.strip()
|
chain_reports.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# chain_reports.py
|
| 2 |
+
from typing import Dict
|
| 3 |
+
from langchain import PromptTemplate, LLMChain
|
| 4 |
+
from models import chat_model
|
| 5 |
+
|
| 6 |
+
report_prompt_template = PromptTemplate(
|
| 7 |
+
input_variables=["qa_summary"],
|
| 8 |
+
template=(
|
| 9 |
+
"You are a wellness assistant. The user provided the following answers:\n\n"
|
| 10 |
+
"{qa_summary}\n\n"
|
| 11 |
+
"Based on these answers, provide a brief, actionable wellness report. "
|
| 12 |
+
"Include simple suggestions to improve their sleep, exercise, stress management, and diet. "
|
| 13 |
+
"Consider recommending wellness packages if applicable based on the user's needs, for instance:\n"
|
| 14 |
+
"- Fitness & Mobility for exercise-related concerns\n"
|
| 15 |
+
"- No More Insomnia for sleep issues\n"
|
| 16 |
+
"- Focus Flow for productivity issues\n"
|
| 17 |
+
"- Boost Energy for low energy\n"
|
| 18 |
+
"- Chronic Care for long-term chronic conditions\n"
|
| 19 |
+
"- Mental Wellness for stress and anxiety reduction\n\n"
|
| 20 |
+
"Also consider aspects of therapy, maintaining a balanced weight, addressing restless nights, "
|
| 21 |
+
"overcoming lack of motivation, improving gut health, managing anxiety, and preventing burnout. "
|
| 22 |
+
"Be concise and helpful.\n\n"
|
| 23 |
+
"Report:"
|
| 24 |
+
)
|
| 25 |
+
)
|
| 26 |
+
report_chain = LLMChain(llm=chat_model, prompt=report_prompt_template)
|
| 27 |
+
|
| 28 |
+
def generate_short_report_for_session(responses: Dict[str, str]) -> str:
|
| 29 |
+
qa_summary = "\n".join(f"{q}: {a}" for q, a in responses.items())
|
| 30 |
+
raw_report = report_chain.run(qa_summary=qa_summary)
|
| 31 |
+
return raw_report.replace("*", "").replace("**", "")
|
chain_summary.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# chain_summary.py
|
| 2 |
+
import json
|
| 3 |
+
from typing import Dict
|
| 4 |
+
from langchain import PromptTemplate, LLMChain
|
| 5 |
+
from models import chat_model
|
| 6 |
+
|
| 7 |
+
final_prompt_template = PromptTemplate(
|
| 8 |
+
input_variables=["report", "problems", "recommendation"],
|
| 9 |
+
template=(
|
| 10 |
+
"Based on the following information:\n"
|
| 11 |
+
"Report:\n{report}\n\n"
|
| 12 |
+
"Problem Severity Percentages:\n{problems}\n\n"
|
| 13 |
+
"Recommended Packages:\n{recommendation}\n\n"
|
| 14 |
+
"Generate a short summary suitable for video narration that synthesizes this information."
|
| 15 |
+
)
|
| 16 |
+
)
|
| 17 |
+
final_chain = LLMChain(llm=chat_model, prompt=final_prompt_template)
|
| 18 |
+
|
| 19 |
+
def generate_final_summary(report: str, problems: Dict[str, float], recommendation: str) -> str:
|
| 20 |
+
summary = final_chain.run(
|
| 21 |
+
report=report,
|
| 22 |
+
problems=json.dumps(problems),
|
| 23 |
+
recommendation=recommendation
|
| 24 |
+
)
|
| 25 |
+
return summary.strip()
|
| 26 |
+
|
| 27 |
+
shorten_prompt_template = PromptTemplate(
|
| 28 |
+
input_variables=["final_summary"],
|
| 29 |
+
template=(
|
| 30 |
+
"Shorten the following summary to make it concise and engaging for video narration. "
|
| 31 |
+
"Ensure all key points remain intact:\n\n"
|
| 32 |
+
"{final_summary}\n\n"
|
| 33 |
+
"Shortened Summary:"
|
| 34 |
+
)
|
| 35 |
+
)
|
| 36 |
+
shorten_chain = LLMChain(llm=chat_model, prompt=shorten_prompt_template)
|
| 37 |
+
|
| 38 |
+
def shorten_summary(final_summary: str) -> str:
|
| 39 |
+
shortened = shorten_chain.run(final_summary=final_summary)
|
| 40 |
+
return shortened.strip()
|
config.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# config.py
|
| 2 |
+
import os
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
logging.basicConfig(level=logging.WARNING)
|
| 6 |
+
logger = logging.getLogger(__name__)
|
| 7 |
+
|
| 8 |
+
def clean_api_key(key: str) -> str:
|
| 9 |
+
return ''.join(c for c in key if ord(c) < 128).strip()
|
| 10 |
+
|
| 11 |
+
for key in ["GEMINI_API_KEY", "GROQ_API_KEY"]:
|
| 12 |
+
if not os.environ.get(key):
|
| 13 |
+
raise ValueError(f"Environment variable {key} is not set.")
|
| 14 |
+
|
| 15 |
+
gemini_api_key = clean_api_key(os.environ["GEMINI_API_KEY"])
|
| 16 |
+
groq_api_key = clean_api_key(os.environ["GROQ_API_KEY"])
|
models.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# models.py
|
| 2 |
+
from google import genai
|
| 3 |
+
from langchain_groq import ChatGroq
|
| 4 |
+
from config import gemini_api_key, groq_api_key
|
| 5 |
+
|
| 6 |
+
client = genai.Client(api_key=gemini_api_key)
|
| 7 |
+
model_name = "gemini-2.0-flash-exp"
|
| 8 |
+
chat_model = ChatGroq(model="Gemma2-9b-It", groq_api_key=groq_api_key)
|
pipeline.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from questions import questions
|
| 2 |
+
from chain_reports import generate_short_report_for_session
|
| 3 |
+
from chain_problems import analyze_problems_with_chain
|
| 4 |
+
from chain_recommendations import generate_recommendations
|
| 5 |
+
from chain_summary import generate_final_summary, shorten_summary
|
| 6 |
+
from typing import Dict
|
| 7 |
+
|
| 8 |
+
def process_answers_pipeline(responses: Dict[str, str]) -> Dict[str, any]:
|
| 9 |
+
"""
|
| 10 |
+
Orchestrates the entire pipeline:
|
| 11 |
+
1. Generates a short wellness report based on responses.
|
| 12 |
+
2. Analyzes problems using the generated report.
|
| 13 |
+
3. Generates package recommendations.
|
| 14 |
+
4. Creates a final summary for video narration.
|
| 15 |
+
5. Shortens the final summary for concise video creation.
|
| 16 |
+
|
| 17 |
+
Returns a dictionary containing all outputs.
|
| 18 |
+
"""
|
| 19 |
+
# Step 1: Generate Report
|
| 20 |
+
report = generate_short_report_for_session(responses)
|
| 21 |
+
|
| 22 |
+
# Step 2: Analyze Problem Severity
|
| 23 |
+
problems = analyze_problems_with_chain(responses, report)
|
| 24 |
+
|
| 25 |
+
# Step 3: Generate Recommendations
|
| 26 |
+
recommendation = generate_recommendations(problems)
|
| 27 |
+
|
| 28 |
+
# Step 4: Generate Final Summary
|
| 29 |
+
final_summary = generate_final_summary(report, problems, recommendation)
|
| 30 |
+
|
| 31 |
+
# Step 5: Shorten Summary for Video
|
| 32 |
+
shortened_summary = shorten_summary(final_summary)
|
| 33 |
+
|
| 34 |
+
# Compile all results
|
| 35 |
+
return {
|
| 36 |
+
"report": report,
|
| 37 |
+
"problems": problems,
|
| 38 |
+
"recommendation": recommendation,
|
| 39 |
+
"final_summary": final_summary,
|
| 40 |
+
"shortened_summary": shortened_summary
|
| 41 |
+
}
|
questions.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# questions.py
|
| 2 |
+
questions = [
|
| 3 |
+
"How many hours of sleep do you get each night?",
|
| 4 |
+
"How often do you exercise in a week?",
|
| 5 |
+
"On a scale of 1 to 10, how would you rate your mood today?",
|
| 6 |
+
"What is your current stress level on a scale from 1 to 10?",
|
| 7 |
+
"What are your primary wellness goals?",
|
| 8 |
+
"Do you follow any specific diet or have any dietary restrictions?",
|
| 9 |
+
"How would you describe your current eating habits?",
|
| 10 |
+
"How much time do you spend on relaxation or mindfulness activities daily?",
|
| 11 |
+
"Do you experience any recurring health issues or pain?",
|
| 12 |
+
"How do you manage stress on a daily basis?",
|
| 13 |
+
"What does your typical daily routine look like?",
|
| 14 |
+
"Do you have a regular bedtime routine to help you sleep better?",
|
| 15 |
+
"How much water do you drink on average per day?",
|
| 16 |
+
"How often do you practice mindfulness or meditation each week?",
|
| 17 |
+
"Do you have a positive or negative mindset most of the time?",
|
| 18 |
+
"How often do you reflect on your personal growth and accomplishments?",
|
| 19 |
+
"How often do you take breaks throughout the day to recharge?",
|
| 20 |
+
"How often do you engage in activities that help you relax or unwind?",
|
| 21 |
+
"On a scale from 1 to 10, how much time do you dedicate to self-care each week?",
|
| 22 |
+
"How often do you engage in outdoor activities or nature walks?",
|
| 23 |
+
"How often do you practice gratitude or keep a gratitude journal?",
|
| 24 |
+
"How often do you eat home-cooked meals each week?",
|
| 25 |
+
"On average, how many hours of uninterrupted sleep do you get?",
|
| 26 |
+
"How often do you experience feelings of gratitude or happiness?",
|
| 27 |
+
"On a scale from 1 to 10, how connected do you feel to your friends and family?",
|
| 28 |
+
"How often do you track your physical activity or steps each day?",
|
| 29 |
+
"Do you regularly include strength training or resistance exercises in your routine?",
|
| 30 |
+
"On a scale from 1 to 10, how would you rate your energy levels throughout the day?"
|
| 31 |
+
]
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
langchain
|
| 3 |
+
langchain_community
|
| 4 |
+
langchain_groq
|
| 5 |
+
google-generativeai
|
| 6 |
+
requests
|
| 7 |
+
google-genai
|