DrishtiSharma commited on
Commit
b5be006
Β·
verified Β·
1 Parent(s): ddd63af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -60,9 +60,15 @@ def run_graph(input_message, history, user_details):
60
  logger.debug("Workflow response: %s", response)
61
  debug_logs.append(f"Workflow Response: {response}")
62
 
63
- # Check and return tailored response
64
- if "messages" in response and len(response["messages"]) > 1:
65
- q.put(response["messages"][1].get("content", "No content in response."))
 
 
 
 
 
 
66
  else:
67
  q.put("The workflow did not return a valid response. Please try again.")
68
  except Exception as e:
@@ -121,8 +127,10 @@ def visualize_bmi_and_calories(bmi, calories):
121
 
122
  # Save visualization to a temporary file
123
  temp_file = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
124
- plt.savefig(temp_file.name)
125
- plt.close()
 
 
126
 
127
  return temp_file.name
128
 
@@ -134,20 +142,21 @@ def calculate_calories(age, weight, height, activity_level, gender):
134
  bmr = 10 * weight + 6.25 * height - 5 * age - 161
135
 
136
  activity_multipliers = {
137
- "Sedentary": 1.2,
138
- "Lightly active": 1.375,
139
- "Moderately active": 1.55,
140
- "Very active": 1.725,
141
- "Extra active": 1.9,
142
  }
143
 
 
144
  return bmr * activity_multipliers.get(activity_level, 1.2)
145
 
146
  # Interface Components
147
  with gr.Blocks() as demo:
148
  gr.Markdown("<strong>FIT.AI - Your Fitness and Wellbeing Coach</strong>")
149
 
150
- debug_logs = [] # Store debug logs
151
 
152
  with gr.Tabs():
153
  with gr.Tab("Visualization + Chat"):
 
60
  logger.debug("Workflow response: %s", response)
61
  debug_logs.append(f"Workflow Response: {response}")
62
 
63
+ # Extract LLM response
64
+ llm_response = None
65
+ for msg in response.get("messages", []):
66
+ if isinstance(msg, HumanMessage) and msg.name in ["nutritionist", "workout_coach"]:
67
+ llm_response = msg.content
68
+ break
69
+
70
+ if llm_response:
71
+ q.put(llm_response)
72
  else:
73
  q.put("The workflow did not return a valid response. Please try again.")
74
  except Exception as e:
 
127
 
128
  # Save visualization to a temporary file
129
  temp_file = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
130
+ try:
131
+ plt.savefig(temp_file.name)
132
+ finally:
133
+ plt.close()
134
 
135
  return temp_file.name
136
 
 
142
  bmr = 10 * weight + 6.25 * height - 5 * age - 161
143
 
144
  activity_multipliers = {
145
+ "sedentary": 1.2,
146
+ "lightly active": 1.375,
147
+ "moderately active": 1.55,
148
+ "very active": 1.725,
149
+ "extra active": 1.9,
150
  }
151
 
152
+ activity_level = activity_level.lower()
153
  return bmr * activity_multipliers.get(activity_level, 1.2)
154
 
155
  # Interface Components
156
  with gr.Blocks() as demo:
157
  gr.Markdown("<strong>FIT.AI - Your Fitness and Wellbeing Coach</strong>")
158
 
159
+ debug_logs = []
160
 
161
  with gr.Tabs():
162
  with gr.Tab("Visualization + Chat"):