dexter commited on
Commit ·
bfdccc9
1
Parent(s): 92bfcd1
change way of data trimming to keep recent
Browse files- app.py +10 -8
- db_agent.py +5 -2
app.py
CHANGED
|
@@ -10,7 +10,8 @@ Sport: Competitive Runner (5K and 10K distances)
|
|
| 10 |
Fitness Goal: Improve VO₂ max and running economy; integrate more strength training to prevent injury.
|
| 11 |
Nutrition Goal: Optimize carbohydrate timing for endurance training; maintain a plant-forward diet rich in iron, B12, and omega-3s.
|
| 12 |
Dietary Preferences: Vegetarian — avoids all meat and fish, consumes dairy and eggs in moderation, prefers whole, minimally processed plant-based foods.
|
| 13 |
-
|
|
|
|
| 14 |
Weekly Fitness Routine:
|
| 15 |
Monday: Easy recovery run (4 miles); yoga
|
| 16 |
Tuesday: Tempo run (6 miles) + lower-body strength (goblet squats, deadlifts, step-ups)
|
|
@@ -51,7 +52,8 @@ Sport: Football (Wide Receiver)
|
|
| 51 |
Fitness Goal: Improve explosive speed and agility; reduce body fat by 3% for better quickness on the field.
|
| 52 |
Nutrition Goal: Increase lean protein intake to support muscle recovery and maintain strength while cutting; reduce processed carbs and increase hydration.
|
| 53 |
Dietary Preferences: Omnivorous with allergies to peanuts and soy—avoids all nut-based and soy-based products, relies on other protein sources like poultry, eggs, and lentils.
|
| 54 |
-
|
|
|
|
| 55 |
Weekly Fitness Routine:
|
| 56 |
Monday: Sprint intervals + agility ladder drills; upper-body strength (bench press, rows, push-ups)
|
| 57 |
Tuesday: Plyometrics + resistance band drills; core stability work
|
|
@@ -92,7 +94,8 @@ Sport: Ice Hockey (Defenseman)
|
|
| 92 |
Fitness Goal: Enhance core stability and upper-body power for better puck control and physical play.
|
| 93 |
Nutrition Goal: Maintain high caloric intake to match energy expenditure during training; focus on anti-inflammatory foods for recovery.
|
| 94 |
Dietary Preferences: Omnivorous — enjoys a wide variety of foods including traditional Korean dishes, prioritizes whole foods with a focus on omega-3s and antioxidants.
|
| 95 |
-
|
|
|
|
| 96 |
Weekly Fitness Routine:
|
| 97 |
Monday: Upper-body hypertrophy (pull-ups, bench press, cable rows); core circuits
|
| 98 |
Tuesday: On-ice practice (drills, power skating, stick handling)
|
|
@@ -135,7 +138,7 @@ step2 = [
|
|
| 135 |
]
|
| 136 |
|
| 137 |
step3 = [
|
| 138 |
-
"
|
| 139 |
"Update Weekly Exercise Routine",
|
| 140 |
"Update Full Report",
|
| 141 |
"Next Steps",
|
|
@@ -216,11 +219,11 @@ def render_bottom():
|
|
| 216 |
if st.session_state.stage == 1:
|
| 217 |
st.markdown("Please select a profile to start:")
|
| 218 |
left, middle, right = st.columns(3)
|
| 219 |
-
left.button("Sofia Rivera", key="sofia", on_click=set_state, args=[{"stage": 2, "personinfo": p1+p1_metabolomics, "messages": {
|
| 220 |
"role": "assistant", "content": "Here are the profile details for Sofia Rivera:\n%s" % p1}}], use_container_width=True)
|
| 221 |
-
middle.button("Marcus Thompson", key="marcus", on_click=set_state, args=[{"stage": 2, "personinfo": p2+p2_metabolomics, "messages": {
|
| 222 |
"role": "assistant", "content": "Here are the profile details for Marcus Thompson:\n%s" % p2}}], use_container_width=True)
|
| 223 |
-
right.button("Jackson Lee", key="jackson", on_click=set_state, args=[{"stage": 2, "personinfo": p3+p3_metabolomics, "messages": {
|
| 224 |
"role": "assistant", "content": "Here are the profile details for Jackson Lee:\n%s" % p3}}], use_container_width=True)
|
| 225 |
if st.session_state.stage == 2:
|
| 226 |
st.markdown("What further information would you like to view?")
|
|
@@ -248,7 +251,6 @@ def render_bottom():
|
|
| 248 |
if q == step3[3]:
|
| 249 |
st.session_state.stage = 4
|
| 250 |
st.rerun()
|
| 251 |
-
print(q)
|
| 252 |
st.session_state.messages.append(
|
| 253 |
{"role": "user", "content": q})
|
| 254 |
resp = query_rag(
|
|
|
|
| 10 |
Fitness Goal: Improve VO₂ max and running economy; integrate more strength training to prevent injury.
|
| 11 |
Nutrition Goal: Optimize carbohydrate timing for endurance training; maintain a plant-forward diet rich in iron, B12, and omega-3s.
|
| 12 |
Dietary Preferences: Vegetarian — avoids all meat and fish, consumes dairy and eggs in moderation, prefers whole, minimally processed plant-based foods.
|
| 13 |
+
'''
|
| 14 |
+
p1_detail = '''
|
| 15 |
Weekly Fitness Routine:
|
| 16 |
Monday: Easy recovery run (4 miles); yoga
|
| 17 |
Tuesday: Tempo run (6 miles) + lower-body strength (goblet squats, deadlifts, step-ups)
|
|
|
|
| 52 |
Fitness Goal: Improve explosive speed and agility; reduce body fat by 3% for better quickness on the field.
|
| 53 |
Nutrition Goal: Increase lean protein intake to support muscle recovery and maintain strength while cutting; reduce processed carbs and increase hydration.
|
| 54 |
Dietary Preferences: Omnivorous with allergies to peanuts and soy—avoids all nut-based and soy-based products, relies on other protein sources like poultry, eggs, and lentils.
|
| 55 |
+
'''
|
| 56 |
+
p2_detail = '''
|
| 57 |
Weekly Fitness Routine:
|
| 58 |
Monday: Sprint intervals + agility ladder drills; upper-body strength (bench press, rows, push-ups)
|
| 59 |
Tuesday: Plyometrics + resistance band drills; core stability work
|
|
|
|
| 94 |
Fitness Goal: Enhance core stability and upper-body power for better puck control and physical play.
|
| 95 |
Nutrition Goal: Maintain high caloric intake to match energy expenditure during training; focus on anti-inflammatory foods for recovery.
|
| 96 |
Dietary Preferences: Omnivorous — enjoys a wide variety of foods including traditional Korean dishes, prioritizes whole foods with a focus on omega-3s and antioxidants.
|
| 97 |
+
'''
|
| 98 |
+
p3_detail = '''
|
| 99 |
Weekly Fitness Routine:
|
| 100 |
Monday: Upper-body hypertrophy (pull-ups, bench press, cable rows); core circuits
|
| 101 |
Tuesday: On-ice practice (drills, power skating, stick handling)
|
|
|
|
| 138 |
]
|
| 139 |
|
| 140 |
step3 = [
|
| 141 |
+
"Give an Updated Dedicated Meal Plan",
|
| 142 |
"Update Weekly Exercise Routine",
|
| 143 |
"Update Full Report",
|
| 144 |
"Next Steps",
|
|
|
|
| 219 |
if st.session_state.stage == 1:
|
| 220 |
st.markdown("Please select a profile to start:")
|
| 221 |
left, middle, right = st.columns(3)
|
| 222 |
+
left.button("Sofia Rivera", key="sofia", on_click=set_state, args=[{"stage": 2, "personinfo": p1+p1_detail+p1_metabolomics, "messages": {
|
| 223 |
"role": "assistant", "content": "Here are the profile details for Sofia Rivera:\n%s" % p1}}], use_container_width=True)
|
| 224 |
+
middle.button("Marcus Thompson", key="marcus", on_click=set_state, args=[{"stage": 2, "personinfo": p2+p2_detail+p2_metabolomics, "messages": {
|
| 225 |
"role": "assistant", "content": "Here are the profile details for Marcus Thompson:\n%s" % p2}}], use_container_width=True)
|
| 226 |
+
right.button("Jackson Lee", key="jackson", on_click=set_state, args=[{"stage": 2, "personinfo": p3+p3_detail+p3_metabolomics, "messages": {
|
| 227 |
"role": "assistant", "content": "Here are the profile details for Jackson Lee:\n%s" % p3}}], use_container_width=True)
|
| 228 |
if st.session_state.stage == 2:
|
| 229 |
st.markdown("What further information would you like to view?")
|
|
|
|
| 251 |
if q == step3[3]:
|
| 252 |
st.session_state.stage = 4
|
| 253 |
st.rerun()
|
|
|
|
| 254 |
st.session_state.messages.append(
|
| 255 |
{"role": "user", "content": q})
|
| 256 |
resp = query_rag(
|
db_agent.py
CHANGED
|
@@ -156,14 +156,17 @@ def query_rag(query_text: List[str], personinfo):
|
|
| 156 |
results = vector_store.similarity_search_with_score(query_text[-1], k=5)
|
| 157 |
|
| 158 |
previous_conversation = "\n\n---\n\n".join(query_text[:-1])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
context_text = "previous conversation:"+previous_conversation + \
|
| 160 |
"\n\n---\n\n".join([doc.page_content for doc, _score in results])
|
| 161 |
prompt_template = ChatPromptTemplate.from_template(PROMPT_TEMPLATE)
|
| 162 |
retrival = generate_sql_query(client, personinfo)
|
| 163 |
prompt = prompt_template.format(
|
| 164 |
user_context=personinfo, context=context_text, hmdb_info=retrival, question=query_text)
|
| 165 |
-
|
| 166 |
-
response_text = client.invoke(prompt[:6000])
|
| 167 |
|
| 168 |
sources = [doc.metadata.get("id", None) for doc, _score in results]
|
| 169 |
formatted_response = f"Response: {response_text}\nSources: {sources}"
|
|
|
|
| 156 |
results = vector_store.similarity_search_with_score(query_text[-1], k=5)
|
| 157 |
|
| 158 |
previous_conversation = "\n\n---\n\n".join(query_text[:-1])
|
| 159 |
+
# trim the last 4000 characters of the previous conversation
|
| 160 |
+
if len(previous_conversation) > 4000:
|
| 161 |
+
previous_conversation = previous_conversation[-4000:]
|
| 162 |
+
|
| 163 |
context_text = "previous conversation:"+previous_conversation + \
|
| 164 |
"\n\n---\n\n".join([doc.page_content for doc, _score in results])
|
| 165 |
prompt_template = ChatPromptTemplate.from_template(PROMPT_TEMPLATE)
|
| 166 |
retrival = generate_sql_query(client, personinfo)
|
| 167 |
prompt = prompt_template.format(
|
| 168 |
user_context=personinfo, context=context_text, hmdb_info=retrival, question=query_text)
|
| 169 |
+
response_text = client.invoke(prompt)
|
|
|
|
| 170 |
|
| 171 |
sources = [doc.metadata.get("id", None) for doc, _score in results]
|
| 172 |
formatted_response = f"Response: {response_text}\nSources: {sources}"
|