DrishtiSharma commited on
Commit
5fb305a
Β·
verified Β·
1 Parent(s): 8ba80f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -26,11 +26,17 @@ logger = logging.getLogger(__name__)
26
  def run_graph(input_message, history, user_details):
27
  def invoke_workflow(q):
28
  try:
 
 
 
 
 
 
29
  system_prompt = (
30
  "You are a fitness and health assistant. "
31
- "Provide actionable, tailored advice based on the user's personal details and goals. "
32
- "Incorporate BMI and daily caloric needs into your suggestions. "
33
- "Offer steps for achieving goals like weight loss or fitness improvement."
34
  )
35
 
36
  # Summarize user details
@@ -46,7 +52,7 @@ def run_graph(input_message, history, user_details):
46
  # Messages for the workflow
47
  messages = [
48
  {"role": "system", "content": system_prompt},
49
- {"role": "user", "content": f"User details: {user_details_summary}"},
50
  {"role": "user", "content": input_message}
51
  ]
52
 
@@ -55,7 +61,7 @@ def run_graph(input_message, history, user_details):
55
  # Extract LLM response
56
  llm_response = None
57
  for msg in response.get("messages", []):
58
- if isinstance(msg, HumanMessage) and msg.name in ["nutritionist", "workout_coach"]:
59
  llm_response = msg.content
60
  break
61
 
@@ -204,7 +210,7 @@ with gr.Blocks() as demo:
204
 
205
  history.append(("User", message))
206
  if isinstance(response, str):
207
- history.append(("FIT.AI", response))
208
  else:
209
  history.append(("FIT.AI", "An unexpected response was received."))
210
 
 
26
  def run_graph(input_message, history, user_details):
27
  def invoke_workflow(q):
28
  try:
29
+ # Determine if the query is general or personal
30
+ if "how" in input_message.lower() or "what" in input_message.lower():
31
+ general_query = True if "general" in input_message.lower() else False
32
+ else:
33
+ general_query = False
34
+
35
  system_prompt = (
36
  "You are a fitness and health assistant. "
37
+ "If the user's query is personal, provide tailored advice based on their details, including BMI and caloric needs. "
38
+ "If the query is general, respond broadly without relying on personal metrics. "
39
+ "Encourage the user to ask follow-up questions and maintain a conversational tone."
40
  )
41
 
42
  # Summarize user details
 
52
  # Messages for the workflow
53
  messages = [
54
  {"role": "system", "content": system_prompt},
55
+ {"role": "user", "content": f"User details: {user_details_summary}" if not general_query else "General query"},
56
  {"role": "user", "content": input_message}
57
  ]
58
 
 
61
  # Extract LLM response
62
  llm_response = None
63
  for msg in response.get("messages", []):
64
+ if isinstance(msg, HumanMessage) and msg.name in ["nutritionist", "workout_coach", "general_expert"]:
65
  llm_response = msg.content
66
  break
67
 
 
210
 
211
  history.append(("User", message))
212
  if isinstance(response, str):
213
+ history.append(("FIT.AI", response + "\nLet me know if there's anything else you'd like to ask! 😊"))
214
  else:
215
  history.append(("FIT.AI", "An unexpected response was received."))
216