Update mylab/pcv.py
Browse files- mylab/pcv.py +76 -90
mylab/pcv.py
CHANGED
@@ -114,95 +114,81 @@ def calculate_calories(age, weight, height, activity_level, gender):
|
|
114 |
with gr.Blocks() as demo:
|
115 |
gr.Markdown("<strong>FIT.AI - Your Fitness and Wellbeing Coach</strong>")
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
calculate_button = gr.Button("Calculate")
|
195 |
-
|
196 |
-
def calculate_metrics(age, weight, height, gender, activity_level):
|
197 |
-
bmi, status = calculate_bmi(height, weight)
|
198 |
-
bmi_path = visualize_bmi_and_calories(bmi, calculate_calories(age, weight, height, activity_level, gender))
|
199 |
-
calories = calculate_calories(age, weight, height, activity_level, gender)
|
200 |
-
return f"Your BMI is {bmi:.2f}, considered {status}.", f"Daily calorie needs: {calories:.2f} kcal", bmi_path
|
201 |
-
|
202 |
-
calculate_button.click(
|
203 |
-
calculate_metrics,
|
204 |
-
inputs=[user_age_calc, user_weight_calc, user_height_calc, user_gender_calc, activity_level_calc],
|
205 |
-
outputs=[bmi_output, calorie_output, bmi_chart]
|
206 |
-
)
|
207 |
|
208 |
demo.launch(share=True)
|
|
|
114 |
with gr.Blocks() as demo:
|
115 |
gr.Markdown("<strong>FIT.AI - Your Fitness and Wellbeing Coach</strong>")
|
116 |
|
117 |
+
# User Info
|
118 |
+
with gr.Row():
|
119 |
+
user_name = gr.Textbox(placeholder="Enter your name", label="Name")
|
120 |
+
user_age = gr.Number(label="Age (years)", value=25, precision=0)
|
121 |
+
user_gender = gr.Dropdown(choices=["Male", "Female"], label="Gender", value="Male")
|
122 |
+
user_weight = gr.Number(label="Weight (kg)", value=70, precision=1)
|
123 |
+
user_height = gr.Number(label="Height (cm)", value=170, precision=1)
|
124 |
+
activity_level = gr.Dropdown(
|
125 |
+
choices=["Sedentary", "Lightly active", "Moderately active", "Very active", "Extra active"],
|
126 |
+
label="Activity Level",
|
127 |
+
value="Moderately active"
|
128 |
+
)
|
129 |
+
|
130 |
+
# Outputs
|
131 |
+
bmi_output = gr.Label(label="BMI Result")
|
132 |
+
calorie_output = gr.Label(label="Calorie Needs")
|
133 |
+
bmi_chart = gr.Image(label="BMI and Calorie Chart")
|
134 |
+
|
135 |
+
chatbot = gr.Chatbot(label="Chat with FIT.AI")
|
136 |
+
text_input = gr.Textbox(placeholder="Type your question here...", label="Your Question")
|
137 |
+
submit_button = gr.Button("Submit")
|
138 |
+
clear_button = gr.Button("Clear Chat")
|
139 |
+
|
140 |
+
def submit_message(message, history=[]):
|
141 |
+
user_details = {
|
142 |
+
"name": user_name.value,
|
143 |
+
"age": user_age.value,
|
144 |
+
"weight": user_weight.value,
|
145 |
+
"height": user_height.value,
|
146 |
+
"activity_level": activity_level.value,
|
147 |
+
"gender": user_gender.value
|
148 |
+
}
|
149 |
+
bmi, status = calculate_bmi(user_details['height'], user_details['weight'])
|
150 |
+
calories = calculate_calories(
|
151 |
+
user_details['age'], user_details['weight'], user_details['height'], user_details['activity_level'], user_details['gender']
|
152 |
+
)
|
153 |
+
chart_path = visualize_bmi_and_calories(bmi, calories)
|
154 |
+
|
155 |
+
# Append metrics to response with actionable advice
|
156 |
+
personalized_metrics = (
|
157 |
+
f"Based on your metrics:\n"
|
158 |
+
f"- BMI: {bmi:.2f} ({status})\n"
|
159 |
+
f"- Daily Caloric Needs: {calories:.2f} kcal\n"
|
160 |
+
f"\nAdvice: "
|
161 |
+
)
|
162 |
+
if status == "underweight":
|
163 |
+
personalized_metrics += "Your BMI indicates you are underweight. Focus on consuming more calories from nutrient-dense foods, including lean proteins, healthy fats, and whole grains. Consider strength training exercises to build muscle mass."
|
164 |
+
elif status == "normal weight":
|
165 |
+
personalized_metrics += "Your BMI is in the normal range. Maintain your weight by balancing calorie intake with regular physical activity. Incorporate a mix of cardio and strength training for overall fitness."
|
166 |
+
elif status == "overweight":
|
167 |
+
personalized_metrics += "Your BMI indicates you are overweight. Aim for a calorie deficit by reducing portion sizes and increasing physical activity. Focus on a diet rich in vegetables, lean protein, and healthy fats."
|
168 |
+
else:
|
169 |
+
personalized_metrics += "Your BMI indicates you are obese. Consult a healthcare provider for a personalized weight loss plan. Start with small, sustainable changes, such as reducing sugary foods and increasing daily physical activity."
|
170 |
+
|
171 |
+
response = personalized_metrics
|
172 |
+
history.append((f"User", message))
|
173 |
+
history.append(("FIT.AI", response))
|
174 |
+
return history, chart_path
|
175 |
+
|
176 |
+
submit_button.click(submit_message, inputs=[text_input, chatbot], outputs=[chatbot, bmi_chart])
|
177 |
+
clear_button.click(lambda: ([], ""), inputs=None, outputs=[chatbot, bmi_chart])
|
178 |
+
|
179 |
+
# Actions
|
180 |
+
calculate_button = gr.Button("Calculate")
|
181 |
+
|
182 |
+
def calculate_metrics(age, weight, height, gender, activity_level):
|
183 |
+
bmi, status = calculate_bmi(height, weight)
|
184 |
+
bmi_path = visualize_bmi_and_calories(bmi, calculate_calories(age, weight, height, activity_level, gender))
|
185 |
+
calories = calculate_calories(age, weight, height, activity_level, gender)
|
186 |
+
return f"Your BMI is {bmi:.2f}, considered {status}.", f"Daily calorie needs: {calories:.2f} kcal", bmi_path
|
187 |
+
|
188 |
+
calculate_button.click(
|
189 |
+
calculate_metrics,
|
190 |
+
inputs=[user_age, user_weight, user_height, user_gender, activity_level],
|
191 |
+
outputs=[bmi_output, calorie_output, bmi_chart]
|
192 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
|
194 |
demo.launch(share=True)
|